简体   繁体   English

从Helper渲染产生“缺少模板”错误

[英]Render from Helper yields “Missing Template” error

In my coupons view, I call a method in helpers/coupons_helper.rb, which in turn invokes a partial with the intent of returning it's output. 在我的优惠券视图中,我在helpers / coupons_helper.rb中调用一个方法,该方法进而调用部分函数以返回其输出。 But I receive a "Missing Template" error. 但是我收到“缺少模板”错误。 Here is the relevant code: 以下是相关代码:

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>

And the error message is: 错误消息是:

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"

The problem turned out to be the leading "_" in the "render" in "new_include". 问题原来是“ new_include”中“ render”中的前导“ _”。 Problem solved. 问题解决了。

You don't prefix the underscore in your render call: 您不能在render调用中为下划线添加前缀:

render "locations_include", :f => builder

On a side-note, it's probably a bit superfluous to add an _include suffix to the file name, since .erb files beginning with an underscore imply that it's a partial. 附带说明一下,在文件名中添加_include后缀可能有点多余,因为.erb文件以下划线开头表示该文件是部分文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM