layout_by_action for Rails Controllers
You might want to specify layouts for individual actions in your controllers.
gem "layout_by_action" to your
Gemfile to get this syntax:
class ExampleController < ApplicationController layout_by_action new: "company", show: "example" end
You can set a default layout.
layout_by_action "default", new: "company", show: "example"
You can also specify an array of actions for any layout.
layout_by_action [:new, :edit] => "company", show: "example"
Extracted from a Rails project by @barelyknown :)
This gem is an answer to a popular question on Stack Overflow.
- Fork it
- 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 new Pull Request