开发者

how am i supposed to handle this?

开发者 https://www.devze.com 2023-03-29 10:49 出处:网络
i am saving a product in my create action, once it is saved i would like it to redirect it to show action like this.

i am saving a product in my create action, once it is saved i would like it to redirect it to show action like this.

if @product.save
  redirect_to :action => :show

and my show action displays the content of the product with the requeste开发者_如何学Pythond id. Since I am redirecting, I would lose all my instance variables. So how to pass the id? Should I use flash for this? Or is there a better way of doing this


The scaffold generator produces code like:

if @product.save
  redirect_to @product
else
  render :new
end

Rails will look to use a product_path pointing to the show action with the :id being @product.id

This assumes you have, in your config/routes.rb

Rails 2.X

map.resources :products

Rails 3.X

resources :products
0

精彩评论

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