2012-07-28 3 views
1

내 모델 중 하나의 의미 론적 양식에 문제가 있습니다. 여기에, 나는 충돌하는 경로를 찾기 위해 rake routes | grep series | grep 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? 

편집 : 해당 모델은 내가 브라우저에서 /series/new를 방문 할 때, 나는 오류가

class Event < ActiveRecord::Base 
    belongs_to :series 
    ... 
end 

class Series < ActiveRecord::Base 
    has_many :events 
    ... 
end 

있습니다 출력 다음 /series/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"} 

템플릿은 다음 부분을 렌더링 :

<% 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에 매핑 된 컨트롤러 동작은 하나뿐입니다.

ActionController::Routing::Routes.draw do |map| 
    map.resources :series, :has_many => :events 
    map.resources :events, :has_many => :rsvps 
end 

이 라우팅 오류의 원인이 될 수있는 것 : 여기

는이 모델에 관련이 config/routes.rb의 일부인가?

+0

'rake routes | grep 시리즈 | grep new'를 사용하여 충돌 경로를 찾습니다. – deefour

+0

예, 충돌 경로가 없습니다 :'new_series_event GET /series/:series_id/events/new(.:format) {: controller => "events", : action => "new"} new_series GET/series/new (: controller => "series", : action => "new"}' – tlehman

+0

질문에 정보를 추가했습니다. 처음에는 "EDIT"부분에 있습니다. – tlehman

답변

1

그냥 직감. 레일의 변곡기를 혼란스럽게 할 수 있습니다. 어쩌면 belongs_to series 대신 belongs_to serial이되어야할까요?

일반적으로 users이 아닌 belongs_to user을 작성합니다. 그래서 당신은 그것을 시도하고 싶을지도 모릅니다.

+0

좋은 생각이지만, 그렇지 않습니다. 굴절 장치는 "일련 번호"를 "일련 번호"로, "시리즈"를 "시리즈"를 복수형으로 매핑합니다. – tlehman

+0

사실, 당신의 직감이 옳았습니다. [이 기사에서] (http://somethinglearned.com/articles/2007/03/19/how-to-uncountable-names-in-restful-routes)는 config.routes의': singular' 옵션을 사용하여 make를 변경할 것을 제안했습니다. 단수 버전은 뚜렷한 단어입니다. 그게 효과, 그것은 '모호한 경로'오류 제거. – tlehman

+0

예! Didnt는 이전에 단수의 옵션에 대해 알고있었습니다. 감사! –