How can I use edit_in_place on three different models from a View for a model those three belong_to?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-05-11T04:08:00Z Indexed on 2010/05/11 4:14 UTC
Read the original article Hit count: 170

Filed under:

I have a model called Campaign. In the controller, I do the following to list, in order, the three Models that belong_to a Campaign:

<% @campaign_events = campaign_events %>
<% @campaign_events.each do |campaign_event| %>
    <% model_name = campaign_event.class.name.tableize.singularize %>
    <p>
        <%= link_to campaign_event.title,  send("#{model_name}_path", campaign_event) %>
        <span class='model_name'>(<%= model_name.capitalize %>)</span> 
        <%= campaign_event.days %> Days
    </p>
<% end %>

campaign_event is a campaign_helper defined as:

module CampaignsHelper
  def campaign_events
    return (@campaign.calls + @campaign.emails + @campaign.letters).sort{|a,b| a.days <=> b.days}
  end
end

I want to be able to click on the numerical value for Days when looking at the view/campaign/show and edit the value for :days (in this case, displayed as campaign_event.days

© Stack Overflow or respective owner

Related posts about edit-in-place