0

Can someone please help me understand params in nested attributes a little better?

I am using Apotomo. But for the example. We could just assume its in the ApplicationController

I have a simple controller show action.

if params[:id].present?
    @menu = Menu.find(params[:id])  
else
    @menu = Menu.first  
end

Which checks to see if a menu id is specified in the URL. If not, it shows the first menu.

This works well as long as I'm only on the /menus/ URL.

But I have nested attributes. So once we visit URL /menus/17/categories/

It finds params[:id] as that of the category, not the menu.

Once I'm nested, I can call :menu_id, and it works fine. But no longer works on the parent object.

How do I look for params[:id] of the menu object regardless of where I am in the URL?

And am I missing something completely?

Here is my routs config as well:

resources :menus, :only => [:show, :home] do
  resources :categories, :only => [:index, :show]
end

Thanks for your patience.

Adam
  • 4,054
  • 4
  • 25
  • 28

1 Answers1

0

I would check how routing is defined. Maybe there is a reason why this link is translated this way.

Zefiryn
  • 2,240
  • 2
  • 20
  • 30
  • Not sure how this would relate to the question. But I edited to add my routes config just in case. thanks... – Adam Nov 09 '11 at 04:01