Redirect issue after update

Aside from the fact that the 'edit' method in the following product_admin_controller is using request.post? instead of creating a separate 'update' method, are there any issues with the code that is immediately apparent and I am overlooking?

  def edit     @product = Product.find(params[:id])     if request.post?       if @product.update_attributes(params[:product])         flash[:notice] = "Success."         redirect_to :action => 'list'         unless @product.styles_valid?           flash[:notice] = "Error."         else           flash[:notice] = "Success."         end       else         flash[:notice] = "Error."         flash[:error_field] = :product       end     end   end

I have tried to insert a raise after request.post? but my application doesn't make contact with this.

Of course, I've ensured my form method is set to "post".

Now what is the exact problem here.

Srikanth Jeeva wrote in post #957743:

Now what is the exact problem here.

My apologies, I seem to have omitted the point of my post o.O

The problem is that the changes are not being saved and it (seemingly) redirects to the site index.

Fine. Can you check the log, copy & paste the params that you get for the action. Also paste the log till redirect occurs.

I have tried to insert a raise after request.post? but my application doesn't make contact with this.

Of course, I've ensured my form method is set to "post".

Hi, Why you want to post your form on same(i.e edit) method..?? As in rails already has CRUD good feature. So y need to custom your form submit flow.?

Anyway.. I would give following solution for you case

1- check that routes.rb file if u have

  map.resources :product_admin

then replace those routes using

  map.with_options :controller => :product_admin do |pp|    pp.edit 'product_admin/edit/:id', :action => :edit    ..    ..ur all methods routes should be here    ..   end

2 - check you edit.html.erb file

add :url => {:action => :edit} in you form tag

One main thing in your controller prefer params[:product_admin] or whatever ur form array instead of request.post?

like

if params[:product_admin]   ... end

I hope this will help you!!

Good Luck :wink:

-Ganesh K

Srikanth Jeeva wrote in post #957747:

Fine. Can you check the log, copy & paste the params that you get for the action. Also paste the log till redirect occurs.

Processing ProductAdminController#edit (for ---.---.-.-- at 2010-10-28 11:41:01) [POST]   Parameters: {"commit"=>"Update", "authenticity_token"=>"W/qBr+JI++GoShT78LvYEl66Cquoq0l4LfdC/mk11Ns=", "id"=>"145", "product"=>{"permalink"=>"multistar-footed-playsuit", "pict ure1_id"=>"1093", "price"=>"18", "name"=>"Multistar Footed Playsuit", "picture6_image_alt"=>"", "vat_exempt"=>"1", "picture5_image_alt"=>"", "fairtrade"=>"1", "organic"=>"1", "m eta_description"=>"something", "picture4_image_alt"=>"", "picture2_image_alt"=>"", "display"=>"0", "picture3_image_alt"=>"", "picture1_image_alt"=>"", "category_ids"=>["26", "61 ", "62", "5", "28", "39", "60"], "meta_tags"=>"", "summary"=>"<p><strong><em>Something...</em></strong></p>\r\n<li>Available in sizes: 0-3, 3-16, 6-12 months </li>\r\n<li>Made from GOTS certified organic cotton </li>\r\n<li>The Fairtrade Mark is your guarantee that small scale cotton farmers are getting a better deal </li>\r\n<li>Pesticide and chemical free </li>\r\n<li>Screen printed by hand using low impact environmentally friendly dyes </li>\r\n<li>We only use nickle free poppers\r\n<p><em><strong></strong></em></p>\r\n</li>", "picture1_remove"=>"0", "product_code"=>"OC-145", "sale_price"=>"", "wholesale_price"=>"9"}}

It then redirects to the index page.

Ganesh Kathare wrote in post #957752:

Hi, Why you want to post your form on same (i.e edit) method? As in rails already has CRUD good feature. So y need to custom your form submit flow?

I asked myself the very same question; it was not me that built the site. I can assure you that if it were me, it would follow the CRUD framework.

Anyway... I would give following solution for you case

1- check that routes.rb file if u have

  map.resources :product_admin

then replace those routes using

  map.with_options :controller => :product_admin do |pp|    pp.edit 'product_admin/edit/:id', :action => :edit    ..    ..ur all methods routes should be here    ..   end

2 - check you edit.html.erb file

add :url => {:action => :edit} in you form tag

One main thing in your controller prefer params[:product_admin] or whatever ur form array instead of request.post?

like

if params[:product_admin]   ... end

I hope this will help you!!

Good luck :wink:

- Ganesh K

Thank you for your response.