القضبان خطأ "قد يكون لديك طرق غامضة"
-
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)
وبهذه الطريقة يعرف التي CLIENT_ID وelement_id لاستخدامها في الطريق
/clients/:client_id/elements/:element_id
لا تنتمي إلى StackOverflow