0

我正在尝试为嵌套路由创建一个编辑页面。

网址类似于:http://localhost:3000/clients/2/notes/3/edit

我的路线.rb:

 resources :clients do
    resources :notes
  end

在我的编辑控制器中:

def edit
  @note = Note.find(params[:id])
  @client = Client.find(params[:client_id])
end

和我的 edit.html.erb 文件

<%= 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 %>

当我这样做并加载编辑页面时,我得到以下信息: 在此处输入图像描述

我环顾了堆栈溢出,并且在使用嵌套路由时它们都有两个参数,这里正确的做法是什么?为什么不一样?

更新:

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
4

1 回答 1

1

尝试使用括号..

<%= form_for([@client, @note]) do |f| %>
于 2012-06-11T16:40:08.093 回答