开发者

how to get ID back from a URL in rails

开发者 https://www.devze.com 2022-12-19 03:42 出处:网络
I have a URL like below /pages/edit_product/11 In my action 开发者_JAVA技巧edit_product how can I get the id 11 So that I can do @p = Product.find_by_id(11)Any parameter passed with url is availabl

I have a URL like below

/pages/edit_product/11

In my action 开发者_JAVA技巧edit_product how can I get the id 11 So that I can do @p = Product.find_by_id(11)


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])
0

精彩评论

暂无评论...
验证码 换一张
取 消