2014-02-28 67 views
0

我有3个嵌套资源:来源,twitter_source和twitter_aggregation_methods。未定义的方法`twitter_source_twitter_aggregation_methods_path'为#<#<Class:0xb982e10>:0xc104ef4>

它们各自的模型的关系如下:

sources.rb

has_many :twitter_sources 

has_many :rss_sources 

twitter_source.rb

has_many :twitter_aggregation_methods 

belongs_to :source 

twitter_aggregation_method.rb

belongs_to :twitter_source 

的config/routes.rb中设置如下:

resources :sources do 
resources :rss_sources 
    resources :twitter_sources do 
    resources :twitter_aggregation_methods 
    resources :influencer_trends do 
     resources :trends 
    end 
    end 
end 

当我尝试添加一个新的twitter_aggreggation_method我得到以下错误:

NoMethodError in TwitterAggregationMethods#new 

Showing /home/notebook/work/abacus/app/views/twitter_aggregation_methods/_form.html.erb where line #1 raised: 

undefined method `twitter_source_twitter_aggregation_methods_path' for #<#<Class:0xb982e10>:0xc104ef4> 

views/twitter_aggregation_methods/_form.html.erb如下:

<%= form_for([@twitter_source, @twitter_aggregation_method]) do |f| %> 
    <% if @twitter_aggregation_method.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@twitter_aggregation_method.errors.count, "error") %> prohibited this twitter_aggregation_method from being saved:</h2> 

    <ul> 
    <% @twitter_aggregation_method.errors.full_messages.each do |msg| %> 
    <li><%= msg %></li> 
    <% end %> 
    </ul> 
</div> 
<% end %> 

<div class="field"> 
    <%= f.label :twitter_source_id %><br> 
    <%= f.text_field :twitter_source_id, value: @twitter_source.id %> 
</div> 
<div class="field"> 
    <%= f.label :aggregation_method %><br> 
    <%= f.text_field :aggregation_method %> 
</div> 
<div class="actions"> 
<%= f.submit %> 

错误指向该部分的第一行。

回答

0

查看定义的资源,twitter_source_twitter_aggregation_methods_path不存在。因此,错误。 您可以使用rake routes并检查prefixes以了解所有路线的存在。

TwitterAggregationMethods#new你会希望去TwitterAggregationMethods#create,对于传递的形式source一个实例,

更换

<%= form_for([@twitter_source, @twitter_aggregation_method]) do |f| %> 

<%= form_for([@source, @twitter_source, @twitter_aggregation_method]) do |f| %> 

,并在设定@sourceTwitterAggregationMethods#new

+0

我改变了表单部分并按照建议的方式创建了我的twitter_aggregation_methods操作。我使用耙路径的前缀更正了twitter_aggregation_method视图中的一些路由问题 – Mutuma

相关问题