我有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 %>
错误指向该部分的第一行。
我改变了表单部分并按照建议的方式创建了我的twitter_aggregation_methods操作。我使用耙路径的前缀更正了twitter_aggregation_method视图中的一些路由问题 – Mutuma