开发者

How to modify the create & update method in RoR?

I know that the after the create or update methods is done, they have the method like this

respond_t开发者_开发知识库o do |format|
  format.js 
end

Since I change my form from remote form to non remote form, so I won't use the format.js anymore, I just want to refresh the page, after the user create/update a product, so I have this code:

respond_to do |format|
  page.reload
end

But it don't work, so I try not to use respond_to do, I only have the page.reload. But it also show me the site like this:

http://localhost:3000/products/50

I just want to reload the page after I create/update, why I can't do it in this way?


The reload method reloads the browser's current location using JavaScript. I would suggest that you probably want to do a server-side redirect after creating or updating your resource. Something like one of these alternatives:

redirect_to product_path(@product) # Redirect to the 'show' page for the product
redirect_to products_path          # Redirect to the products' index page


How can I assign the product_path? in routes.rb?

in routes.db you can either:

  1. map.product 'products/:id', :controller => 'products', :action => 'view'
  2. map.resources :product
  3. map.resource :product

1) will give you product_path(123) and product_url 2) will give you product_path, new_product_path, edit_product_path and so on

HTH

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜