| app/views/paloma | ||
| lib | ||
| spec | ||
| .gitignore | ||
| Gemfile | ||
| Gemfile.lock | ||
| paloma.gemspec | ||
| Rakefile | ||
| README.md | ||
paloma
Javascript Callback Manager for Rails 3
Install
Add the following line to the Gemfile:
gem 'paloma'
Setup
On setup, the paloma folder will be generated in app/assets/javascripts/. Inside this folder, paloma.js and index.js will also be created.
Execute the following command in the terminal:
rails g paloma:setup
Usage
Execute the following command to generate a folder, named as <controller_name>, which will be the container of all the callbacks that will be used within that controller. Inside this folder, callbacks.js will also be generated.
rails g paloma:add <controller_name>
The next command allows the user to create the file <action_name>.js under the <controller_name> folder.
rails g paloma:add <controller_name>/<action_name>
Generated Files
###paloma.js Declaration of namespace used in all callbacks
# app/assets/javascripts/paloma/paloma.js
window.Paloma = {callbacks:{}};
###index.js Contains code for requiring all callbacks of all folders and is automatically updated when new folders and callback.js files are created
# app/assets/javascripts/paloma/index.js
//= require ./paloma
//= require ./<controller_name>/callbacks
###callbacks.js Contains code for requiring all callbacks under the same folder <controller_name>
# app/assets/javascripts/paloma/<controller_name>/callbacks.js
//= require_tree .
###<action_name>.js Actual code to be executed when callback is called
# app/assets/javascripts/paloma/<controller_name>/<action_name>.js
Paloma.callbacks['<controller_name>/<action_name>'] = function(params){
...
//put your code here
...
};