2011-06-27 44 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小时过去,所以我不得不接受我的同龄人对我的嘲笑;)无论如何,感谢您的观察。 –