Hello, I have an Entry model with polymorphic associations with all kinds of contents, like notes, addresses, etc.
Class Entry < ActiveRecord::Base belongs_to :content, :polymorphic => true end
Class Note < ActiveRecord::Base has_one :entry, :as => :content end
Class Address < ActiveRecord::Base has_one :entry, :as => :content end
Now, I am trying to follow the RESTful path, so in routes.rb I have: map.resources :entries, :notes, :addresses, ...
I have an index action in entries_controller that retrieves all @entries and, finally, index.rhtml has the following:
<table> <tr><th>Type</th><th>Title</th></tr> <% for entry in @entries %> <tr> <td><%= entry.content_type %></td> <td><%= link_to entry.content.title, entry_path(entry) %></td> </tr> <% end %> </table>
BUT--here's the thing. I DON'T really want entry_path to generate the linked URL. Rather, I would very much like each individual entry's content type to determine routing. Thus, for example, if entry.content_type is "Note", then I would like notes_controller actions to be invoked, as if I had written the following: <%= link_to entry.content.title, note_path(entry.content_id) %>
Does this make sense? At the very least I am sure the question is going to give away my poor knowledge of Ruby...
Many thanks in advance, Giuseppe Bertini