Watched 1 video

Watched 1 Video from start to finish

Subscribed for 1 month

Learning and showing your support for 1 Month

Spread the word 1 time

Referred 1 Member to Drifting Ruby

10

10 times Chatter Box

Make 10 comments to videos or replies to other comments
1/10

Share the love 1 time

Liked 1 episode

3

Welcome back 3 times

You've visited Drifting Ruby on 3 different days

Suggested 1 episode

Helped the community by suggesting 1 episode

Vote Suggestion 1 time

Helped the community by voting on suggestions 1 time

1 time Chatter Box

Make 1 comment to videos or replies to other comments

Earned on 3/4/2019

# Name
smarquez1 said about 2 years ago on Page Specific Javascript in Ruby on Rails :

Thanks, this is great. I added a couple functions to the init.js file in my project to make the syntax shorter, hope that it helps someone: ``` #init.js var Page, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; Page = (function() { function Page() { this.action = bind(this.action, this); this.controller = bind(this.controller, this); } Page.prototype.controller = function() { return $('meta[name=psj]').attr('controller'); }; Page.prototype.action = function() { return $('meta[name=psj]').attr('action'); }; Page.prototype.isController = function(controller) { return controller === this.controller() }; Page.prototype.isAction = function(action) { return action === this.action() }; Page.prototype.isControllerAndAction = function(controller, action) { return this.isController(controller) && this.isAction(action) }; return Page; })(); this.page = new Page; ``` So then you can do the check like this like this: ``` if(!page.isControllerAndAction('users', 'index')) return;```