1

在我的优惠券视图中,我调用了 helpers/coupons_helper.rb 中的一个方法,该方法又调用了一个partial,目的是返回它的输出。但我收到“缺少模板”错误。以下是相关代码:

views/coupons/show.html.erb:
  ...
  <%= form_for(@coupon) do |f| %>
    <% new_include(f) %>
  <% end %>

helpers/coupons_helper.rb:
  def new_include(f)
    new_object = Participation.new
    fields = f.fields_for(:participation, new_object, :child_index => :new_include) do |builder|
      render "_locations_include", :f => builder
    end
  end

views/coupons/_locations_include.html.erb:
  Include: <%= f.select :participant_id, @groups %><br>

错误信息是:

Missing partial coupons/_locations_include with {:handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/Users/jackrg/Documents/YummiApps/yummi1/app/views"

问题原来是“new_include”中“render”中的前导“_”。问题解决了。

4

1 回答 1

1

您没有在render通话中添加下划线前缀:

render "locations_include", :f => builder

附带说明一下,在文件名中添加后缀可能有点多余_include,因为以下划线开头的 .erb 文件暗示它是部分文件名。

于 2011-06-27T01:52:36.470 回答