ruby-on-railsrestlink-to

link_to with nested resources edit_path


In my routes I have:

    resources :users do
      resources :orders
    end

so when I create a link which leads to 'show' action I can simply make

<%= link_to "Details", [@order.user, @order] %>

But what should I write if I want to make link_to for 'edit' action?

in my orders_controller:

@order = Order.find params[:id]

so I've tried this code:

<%= link_to "Edit", edit_user_order_path([@order.user, @order]) %>

but somehow edit_user_order_path method can't get :id parameter from @order object, error says me:

missing required keys: [:id]

while user_id is returning!


Solution

  • edit_user_order_path(@order.user, @order)