Question

I'm having an issue with my routes and the name of the path it generates. Or I'm naming it wrong in the view or something... not totally sure. My relationships in my models are as follows:

class Client < ActiveRecord::Base
  has_many :users
  has_many :elements, :through => :users 
end

class Element < ActiveRecord::Base
  belongs_to :user
end

My routes are like:

map.resources :elements
map.resources :clients, :has_many => :elements

And in my view I have:

<%= link_to element.name, client_element_url %>

But the error I get is:

    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?

I'm not sure how to proceed, am I missing something that is right in my face?

Was it helpful?

Solution

You need to pass in the element and the client to the url method:

<%= link_to element.name, client_element_url(element.client, element)

This way it knows which client_id and element_id to use in the route

/clients/:client_id/elements/:element_id
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top