parent_resource
in the controller of recursive resource, auto load parent resource
Installation
Add this line to your application's Gemfile:
gem 'parent_resource'
Usage
config/routes.rb
resources :members
resources :projects do
resources :members
end
app/controller/members_controller.rb
# auto load @project when like /projects/1/members
# not load when /members
class MembersController < ActionController::Base
parent_resource :project
end
app/view/members/new.html.erb
# you can support both /projects/1/members/new and /members/new with single file
<% form_for([@project, @member]) do |f| %>
...
<% end %>
Contributing
- Fork it ( https://github.com/masarakki/parent_resource/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