我的路线及其生成的路径名称存在问题。或者我在视图中命名错误或某些东西......不完全确定。我在模型中的关系如下:

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top