views:

26

answers:

1

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

A: 

I'm not really sure about it, but I'll try to help... I believe something like the following may work for you:

# calls controller
in_place_edit_for :call, :days

# emails controller
in_place_edit_for :email, :days

# letters controller
in_place_edit_for :letter, :days

# campaign view
<% @campaign_events = campaign_events %>
<% @campaign_events.each do |campaign_event| %>
   <% controller_name = campaign_event.class.name.tableize %>
   <% model_name = controller_name.singularize %>
   <p>
      <%= link_to campaign_event.title, 
         send("#{model_name}_path", campaign_event) %>

      <span class='model_name'>(<%= model_name.capitalize %>)</span> 

      <%= in_place_editor_field model_name, :days, {}, 
         :url => {
            :controller => controller_name, 
            :action => 'set_#{model_name}_title',
            :id => campaign_event.id} %> Days
   </p>
<% end %>

There's somethings I don't know exactly how to do:

1) in_place_editor_field model_name
I believe this won't work, but I don't know how to pass the model_name.

2) :action => 'set_#{controller_name}_title'
Not sure about it also. Just doesn't look right.

Anyway, hope it helps you... and forgive me if this is completely stupid.

j.
thanks for the effort, it's not quite there...playing around with some of the ideas, though....
Angela