0

我想在显示来自不同模型的值的视图中启用就地编辑功能:

这是我目前使用的,它不起作用,但想要一些替代方案:

我有一个名为 Campaign 的模型。在控制器中,我执行以下操作以按顺序列出belong_to一个活动的三个模型:

<% @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_eventcampaign_helper定义为:

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

我希望能够在查看视图/广告系列/显示时单击天数的数值并编辑:days(在这种情况下,显示为campaign_event.days

4

1 回答 1

0

我不太确定,但我会尽力提供帮助......我相信以下内容可能对您有用:

# 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 %>

有些事情我不知道该怎么做:

1)in_place_editor_field model_name
我相信这行不通,但我不知道如何传递model_name。

2):action => 'set_#{controller_name}_title'
也不确定。只是看起来不太对。

无论如何,希望它可以帮助你......如果这完全是愚蠢的,请原谅我。

于 2010-05-12T01:10:35.243 回答