PerPageLoader
Installation
Add this line to your application's Gemfile:
gem 'per_page_loader'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install per_page_loader
Usage
PerPageLoader lets you attach page specific coffeescript to your rails application using jquery to load the specific coffee class and method that are needed for your controller action.
Setup
After including the gem it is as simple as wrapping your application html in the per_page_container
helper method.
%body
= per_page_container do
= yield
Adding this helper to the layouts will give PerPageLoader access to loading in javascript for every page.
Generators
The PerPageLoader has a specific format of coffeescript controller that it looks for and we have built generators to help build these files for you.
rails generate per_page_loader:controller User
will generate...
# app/assets/javascripts/application/controllers/users_controller.coffee
class UsersController
window.UsersController = UsersController
Auto generating the actions is as easy as passing in the names of the actions.
rails generate per_page_loader:controller User index show
will generate...
# app/assets/javascripts/application/controllers/users_controller.coffee
class UsersController
indexAction: ->
showAction: ->
window.UsersController = UsersController
If it is necessary to change the location that the file is generated the --dir=dir_name
flag can be used.
rails generate per_page_loader:controller User --dir=admin
will generate...
# app/assets/javascripts/admin/controllers/users_controller.coffee
class UsersController
window.UsersController = UsersController
License
The gem is available as open source under the terms of the MIT License.