Here is the relevant line from my rake routes:
client_note GET /clients/:client_id/notes/:id(.:format) notes#show
When I try passing in the objects like <%= client_note_path([client, @notes.first]) %>> I get:
No route matches {:action=>"show", :controller=>"notes",
:client_id=>[#<Client id: 5, ... , #<Note id: 9, ...]}
Which made me think to try a client ID. So, I tried: <%= client_note_path([client.id, @notes.first]) %>
which gives me:
No route matches {:action=>"show", :controller=>"notes", :client_id=>[5,
#<Note id: 9,content: "He just bought a brand new bobcat, be sure to charg...",
client_id: 5, created_at: "2012-06-11 16:18:16",
updated_at: "2012-06-11 16:18:16">]}
Which, made me want to try just passing in a client ID. <%= client_note_path(client.id) %>
No route matches {:action=>"show", :controller=>"notes", :client_id=>5}
Still not what I’m looking for. I want to be able to show an individual note which can normally be found at a url like looks like: http://localhost:3000/clients/2/notes/3/
What object(s) does it expect?
Complete Routes File and Rake Routes
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
client_notes GET /clients/:client_id/notes(.:format) notes#index
POST /clients/:client_id/notes(.:format) notes#create
new_client_note GET /clients/:client_id/notes/new(.:format) notes#new
edit_client_note GET /clients/:client_id/notes/:id/edit(.:format) notes#edit
client_note GET /clients/:client_id/notes/:id(.:format) notes#show
PUT /clients/:client_id/notes/:id(.:format) notes#update
DELETE /clients/:client_id/notes/:id(.:format) notes#destroy
clients GET /clients(.:format) clients#index
POST /clients(.:format) clients#create
new_client GET /clients/new(.:format) clients#new
edit_client GET /clients/:id/edit(.:format) clients#edit
client GET /clients/:id(.:format) clients#show
PUT /clients/:id(.:format) clients#update
DELETE /clients/:id(.:format) clients#destroy
root / clients#index
signup /signup(.:format) users#new
signin /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
And:
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :clients do
resources :notes
end
root to: 'clients#index'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
Additional Info:
Changing the line to <%= client_note_path(client, @notes.first) %> results in:
No route matches {:action=>"show", :controller=>"notes", :client_id=>#<Client id: 6,
company_name: "John and Sons Roofing", contact_name: "John Wonder", phone_number: "1-
555-283-9999", email_address: "bob@example.com", street_address: "13 Oak Street", city:
"Oakville", state: "Iowa", zip: "53457", image_location: "http://image-
location.com/image/john.jpg", created_at: "2012-06-11 16:18:16", updated_at: "2012-06-11
16:18:16", url: "www.johnroofing.com">, :id=>nil}
Which gives me an id of nil. But, I have <%= @notes.first.blank? ? "No Notes" : @notes.first.content%> and that returns the notes content, so I don’t understand why it doesn’t work. Also, let’s try it with id, just for fun! <%= client_note_path(client.id, @notes.first.id) %>
And now we get: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id. Looking into the DB, the ID of the note is 9 and 5 for the client.
I believe your issue is that you are putting the objects into an array as a single parameter rather than just passing two parameters. The proper way is
Note that you can pass in the object itself (as shown), or the id of the object for either or both.