I'm trying to create an edit page for a nested route.
The url is something like: http://localhost:3000/clients/2/notes/3/edit
my routes.rb:
resources :clients do
resources :notes
end
In my edit controller:
def edit
@note = Note.find(params[:id])
@client = Client.find(params[:client_id])
end
and my edit.html.erb file
<%= form_for(@client, @note) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :content %>
<%= f.text_field :content %>
<%= f.submit "Save changes" %>
<% end %>
When I do this and load the edit page, I get the following:
I've looked around on stack overflow and they all have two arguments when using nested routes, what is the correct thing to do here? And why is it different?
Update:
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
Try using brackets..
<%= form_for([@client, @note]) do |f| %>