2011-06-27 45 views
1

在我的優惠券視圖中,我在helpers/coupons_helper.rb中調用了一個方法,該方法依次調用一個部分以返回它的輸出。但是我收到一個「Missing Template」錯誤。下面是相關代碼:Helper渲染會產生「Missing Template」錯誤

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」。問題解決了。

回答

1

你不要在你的render電話前綴下劃線:

render "locations_include", :f => builder 

在一個側面說明,它可能是一個有點畫蛇添足到_include後綴添加到文件名,自始自終與.erb文件一個下劃線意味着它是一個部分。

+0

我會同意你的看法,但我有兩個偏見:一個叫locations_include,另一個叫locations_exclude。在發佈後大約15分鐘後(在發佈之前查看了一小時後),我發現我有一個無關的「_」,但我沒有足夠的狀態在我的問題發佈答案,直到8小時過去,所以我不得不接受我的同齡人對我的嘲笑;)無論如何,感謝您的觀察。 –