Rails 오류 "당신은 모호한 경로가있을 수 있습니다"
-
07-07-2019 - |
문제
나는 내 경로와 그것이 생성하는 경로의 이름에 문제가 있습니다. 또는 나는보기 나 무언가에서 잘못을 명명하고있다. 내 모델에서의 관계는 다음과 같습니다.
class Client < ActiveRecord::Base
has_many :users
has_many :elements, :through => :users
end
class Element < ActiveRecord::Base
belongs_to :user
end
내 경로는 다음과 같습니다.
map.resources :elements
map.resources :clients, :has_many => :elements
그리고 내 견해로는 다음과 같습니다.
<%= link_to element.name, client_element_url %>
그러나 내가 얻는 오류는 다음과 같습니다.
edit_client_element_url failed to generate from {:action=>"edit", :controller=>"elements"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["clients", :client_id, "elements", :id, "edit"] - are they all satisfied?
어떻게 진행 해야할지 잘 모르겠습니다. 내 얼굴에 옳은 것을 놓치고 있습니까?
해결책
요소와 클라이언트를 URL 메소드로 전달해야합니다.
<%= link_to element.name, client_element_url(element.client, element)
이렇게하면 경로에서 사용할 클라이언트 _id 및 element_id를 알고 있습니다.
/clients/:client_id/elements/:element_id
제휴하지 않습니다 StackOverflow