Extend polymorphic_url
to replace simple resource with array of resources.
Add this line to your application's Gemfile:
gem 'susanin'
And then execute:
$ bundle
Or install it yourself as:
$ gem install susanin
By default gems do nothing. Include module 'susanin' to the controller.
class ApplicationController < ActionController::Base
include ::Susanin
susanin do
{
Admin => ->(resource) { [resource.company, resource] },
Photo => ->(resource) { [resource.admin.company, resource.admin, resource] },
Gallery => ->(resource) { [resource.company, resource] }
}
end
end
Then you're able to call link_to
method wihtout knowlege about the nested resources inside routes.rb
. Instead of this:
link_to user.email, [:edit, user.company, user], class: 'button'
You are able to write this:
link_to user.email, [:edit, user], class: 'button'
- Fork it ( https://github.com/[my-github-username]/susanin/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