Before Actions
Organize your controllers by grouping your before and after filters.
Status
References
- Home page: https://github.com/before-actions-gem/before_actions
- API Doc: http://rdoc.info/gems/before_actions
- Version: https://rubygems.org/gems/before_actions
- Trello Board: https://trello.com/b/PMRfJAqq/before-actions-gem
Support
- Bugs/Issues: https://github.com/before-actions-gem/before_actions/issues
- Support: http://stackoverflow.com/questions/tagged/before_actions
- Support/Chat:

Installation
Add this line to your application's Gemfile:
gem 'before_actions'
And then execute:
bundle
rails g before_actions:template
Upgrading from 1.*
bundle update before_actions
rails g before_actions:template
Then simply adjust your controllers to the new syntax
Demo
It's simple!
class ContactsController < ApplicationController
# load and authorize resources
before_actions do
# listing actions
only(:index) { @contacts = Contact.all }
# building actions
only(:new) { @contact = Contact.new }
only(:create) { @contact = Contact.new(contact_params) }
# member actions, will raise a 404 if the model is not found
only(:show, :edit, :update, :destroy) { @contact = Contact.find(params[:id]) }
end
after_actions do
all { your_code_here }
except(:index) { your_code_here }
end
around_actions do
only(:create) do |controller, action|
your_code
action.call
in_here
end
end
...
def contact_params
params.require(:contact).permit(:name)
end
end
Restful Controller

Nested Resourceful Controller

Contributing
- Fork it ( https://github.com/github.com/before-actions-gem/before_actions/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Versioning
Before Actions uses Semantic Versioning 2.0.0



