我的一个模型的语义形式有问题。相关型号为
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
什么可能导致此路由错误?