在我的优惠券视图中,我在helpers / coupons_helper.rb中调用了一个方法,该方法又调用了一个部分,目的是返回它的输出。但是我收到“遗失模板”错误。以下是相关代码:
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”中的前导“_”。问题解决了。
答案 0 :(得分:1)
您不会在render
来电中使用下划线作为前缀:
render "locations_include", :f => builder
另一方面,为文件名添加_include
后缀可能有点多余,因为以下划线开头的.erb文件暗示它是部分的。