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
link_to ‘Edit’, edit_product_path(product, :category =>params

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

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

Thanks a lot.


On Apr 7, 8:24 pm, elliottg removed_email_address@domain.invalid wrote:


You might want to read up on nested resources

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

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



Thanks Fredrick.

The tip on nested routes was just what I needed.

On Apr 7, 4:32 pm, Frederick C. removed_email_address@domain.invalid