0

ネストされたルートの編集ページを作成しようとしています。

URL は次のようなものです。http://localhost:3000/clients/2/notes/3/edit

私のroutes.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 %>

これを行って編集ページをロードすると、次のようになります。 ここに画像の説明を入力

スタック オーバーフローについて調べてみましたが、ネストされたルートを使用する場合、それらはすべて 2 つの引数を持ちます。ここで行う正しいことは何ですか? そして、なぜ違うのですか?

アップデート:

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 に答える