smarquez1 said about 6 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;```