簡體   English   中英

從Helper渲染產生“缺少模板”錯誤

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

在我的優惠券視圖中,我在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”中的前導“ _”。 問題解決了。

您不能在render調用中為下划線添加前綴:

render "locations_include", :f => builder

附帶說明一下,在文件名中添加_include后綴可能有點多余,因為.erb文件以下划線開頭表示該文件是部分文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM