How can I display a list of three different Models sortable by the same :attribute in rails?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-05-09T17:43:35Z Indexed on 2010/05/09 17:48 UTC
Read the original article Hit count: 183

Filed under:
|
|

I have a Campaign model which has_many Calls, Emails, and Letters.

For now, these are each a separate Model with different controllers and actions (although I would like to start to think of ways to collapse them once the models and actions stabilize).

They do share two attributes at least: :days and :title

I would like a way to represent all the Calls, Emails, and Letters that belong_to a specific Campaign as a sortable collection (sortable by :days), in a way that outputs the model name and the path_to() for each.

For example (I know the below is not correct, but it represents the kind of output/format I've been trying to do:

@campaign_events.each do |campaign_event|
  <%= campaign_event.model_name %>
  <%= link_to campaign_event.title, #{model_name}_path(campaign_event) %>
end

Thanks so much. BTW, if this matters, I would then want to make the :days attribute editable_in_place.

© Stack Overflow or respective owner

Related posts about models

Related posts about collections