Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get ID back from a URL in rails

I have a URL like below

/pages/edit_product/11

In my action edit_product how can I get the id 11 So that I can do @p = Product.find_by_id(11)

like image 371
Katyal Avatar asked Jan 30 '10 18:01

Katyal


1 Answers

Any parameter passed with url is available in the controller action and views in params hash.

To grab the id from the url, you can do params[:id] in your controller#edit_product action or view. So you can get the product by

@p = Product.find_by_id(params[:id])
like image 131
nas Avatar answered Oct 06 '22 00:10

nas