我遇到了我的模型之一的语义形式的问题。相关模型为什么我得到“你可能有含糊不清的路线”的轨道控制器行动?
class Event < ActiveRecord::Base
belongs_to :series
...
end
class Series < ActiveRecord::Base
has_many :events
...
end
当我在浏览器中访问/series/new
,我得到的错误:
series_url failed to generate from {:controller=>"series", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["series", :id] - are they all satisfied?
编辑:我已经运行rake routes | grep series | grep new
寻找冲突的路线,没有,这里是输出:
new_series_event GET /series/:series_id/events/new(.:format) {:controller=>"events", :action=>"new"}
new_series GET /series/new(.:format) {:controller=>"series", :action=>"new"}
对应于/series/new
模板呈现以下部分:
<% semantic_form_for(@series) do |f| %>
<%= f.error_messages %>
<% f.inputs do %>
<%= f.input :title %>
<%= f.input :uri, :label => "URL of the Series", :hint => "For example, use 'tes' for 'Transportation Education Series'. It will appear as http://events.kittelson.com/tes" <%= f.input :description %>
<%= f.input :contact, :label => "Contact email" %>
<%= f.input :color, :label => "Pick a dark color" %>
<% end %>
<% f.buttons do %>
<%= f.commit_button %>
<%= link_to "or cancel", :back %>
<% end %>
<% end %>
其中@series
对象在控制器中被定义为Series.new
。
我不明白的是,这是如何涉及到路由,我跑rake routes
,并且只有一个控制器动作映射到/series/new
。
这里是config/routes.rb
的部分,涉及到这些模型:
ActionController::Routing::Routes.draw do |map|
map.resources :series, :has_many => :events
map.resources :events, :has_many => :rsvps
end
什么导致这个路由错误?
你有没有像'rake routes | grep系列| grep new'来寻找冲突的路线? – deefour 2012-07-28 00:41:24
是的,没有冲突的路线:'new_series_event GET /series/:series_id/events/new(.:format){:controller =>“events”,:action =>“new”} new_series GET/series/new (。:format){:controller =>“series”,:action =>“new”}' – tlehman 2012-07-28 00:43:15
我已将该信息添加到问题中,它接近开头,在“编辑”下。 – tlehman 2012-07-28 01:41:48