开发者

How can I use do edit-in-place on three different models from a View for a model those three belong_to?

I would like to enable edit-in-place functionality in a View that displays values from different models:

This is what I use currently and it does NOT work, but would like some alternatives:

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 + @c开发者_JAVA百科ampaign.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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜