ActionController::Parents
Easily access parent resources.
Installation
Add this line to your application's Gemfile:
gem 'action_controller-parents'
And then execute:
$ bundle
Or install it yourself as:
$ gem install action_controller-parents
Usage
Extend your ApplicationController
with the
ActionController::Parents::Methods
module and use parent_resources
:
class ApplicationController < ActionController::Base
extend ActionController::Parents::Methods
end
class MembersController < ApplicationController
parent_resources Group, Organization
# GET /organizations/:organization_id/members
# GET /groups/:group_id/members
def index
@members = parent_resource.members
end
end
Or use ActionController::Parents
directly:
class MembersController < ActionController::Base
include ActionController::Parents.new(Organization, Group)
# GET /organizations/:organization_id/members
# GET /groups/:group_id/members
def index
@members = parent_resource.members
end
end
Contributing
- 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