Rails will infer the path name from the object type. If you pass a Foo
object, it will use foo_path
. If you pass a FooBar
object, it will use foo_bar_path
.
<%= link_to 'foo', foo %>
Assuming foo
is one of either a Foo
or a FooBar
object.
I cover this in-depth in my blog post called "Polymorphic Routes".