Best practice for passing vars etc...

I am new to rails and I am having a hard time coming up with a clean solution to handle passing vars to controllers and views so that they will have the data they need to function correctly.

For instance. I have products_controller. This controller manages a Product model, and Product belongs_to Category.

Within products_controller all CRUD actions are scoped thru the Categories has_many association IE:

category = Category.find_by_name params[:category] @product = category.products.find(params[:id])

In order for the products_controller actions to operate they all need access to params[:category]. Currently I am passing that attribute around thru a combination of hidden for_for fields and stuff like this: link_to 'Edit', edit_product_path(product, :category =>params [:category])

I am running into a lot of issues keeping track of passing this info around through the various views and actions that are in play. It feels sloppy and prone to problems. It's like I'm working in PHP again.

Should I use global varibles or sessions to solve these kinds of problems? Whats the best thing to do here?

Thanks a lot.

In order for the products_controller actions to operate they all need access to params[:category]. Currently I am passing that attribute around thru a combination of hidden for_for fields and stuff like this: link_to 'Edit', edit_product_path(product, :category =>params [:category])

I am running into a lot of issues keeping track of passing this info around through the various views and actions that are in play. It feels sloppy and prone to problems. It's like I'm working in PHP again.

You might want to read up on nested resources

Should I use global varibles or sessions to solve these kinds of problems?

I really wouldn't - that's definitely grungy (both server side and from the point of view of the user)

Fred

Thanks Fredrick.

The tip on nested routes was just what I needed.