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
精彩评论