Work with friendly_id
preston opened this issue · comments
The friendly_id gem is really handy for creating user-readable resource paths, and the master branch now works with Rails 4 as well. Currently, a before_action must be set in order to call the `find' defined by friendly_id instead of ActiveRecord's, like so:
before_action :set_foo, only: [:show, :edit, :update, :destroy]
def foo
@foo = Foo.friendly.find(params[:id])
end
It would be really nice if inherited_resources could check for the presence of Foo.friendly and use Foo.friendly.find instead, allowing DRYer controllers when both are present!
That's a pretty specific request which doesn't really belong in IR. As you pointed out, it can already be done using a before_action
.
I too would like to see integration with friendly_id, but as a workaround that doesn't require the before_action, you can simply add :use => [:slugged, :finders]
to your model to overwrite .find
.
Hi,
You also can override your controller like this :
defaults resource_class: User.friendly