ruby on rails - Redirect making a PATCH request instead of GET -


i'm making ajax patch request application.js file:

$.ajax({      type: "patch",      url: "/units/" + id,      data: { 'var_1': var_1,              'var_2': var_2,},      success:function(){             alert("details saved successfully!!!");      },      datatype: "text"  });   // stop normal form submission behaviour  $("#add_form").submit(function(e){ return false; });  

this request received controller, , attributes of object updated. try redirect index page particular id.

units_controller.rb

if @unit.update_attributes( ** data ** )     flash.notice = "successfully updated "     redirect_to :controller => "/units", :action => "index", :id => params[:id] end 

my issue redirect_to call contains patch method request , therefore returns routing error. should request, per routes.rb file:

resources :units, except: :show '/units/index' => 'units#index' 

any idea why redirect_to call contains patch method request , how change get?

"if using xhr requests other or post , redirecting after request browsers follow redirect using original request method. may lead undesirable behavior such double delete. work around can return 303. see other status code followed using request." taken api documentation of actioncontroller::redirecting#redirect_to.
btw. redirecting in situation not appropriate solution. better should render appropriate template or update resource instead of resources(if possible).


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -