views:

48

answers:

2

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

respond_to 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?

+1  A: 

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
John Topley
How can I assign the product_path? in routes.rb?
Ted Wong
I have some question here, I don't have the product model,I only have the controllers, helpers and view.
Ted Wong
What models do you have?
John Topley
A: 

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

Nazar