I have a polymorphic association that looks like this:
class Line < ActiveRecord::Base
belongs_to :item, :polymorphic => true
end
class Education < ActiveRecord::base
has_many :lines, :as => :item
end
class Work < ActiveRecord::base
has_mayn :lines, :as => :item
end
I'd like a simple way to create a new Line from the parent Item. So, I might be editing a view for a Work object, and want to have a link that creates a new Line object. Normally, I would do this:
<%= link_to "New Line", new_work_line_path(@work) %>
And the helper would work the route for this. However, this requires that I check which parent the Line belongs to in the controller, defeating the purpose of polymorphism (I could have used two references if that were the case). So, my question is, how do I get the path to work polymorphically like a normal path helper?