开发者

remote_function keeps adding authenticity token on GET requests

开发者 https://www.devze.com 2022-12-27 09:32 出处:网络
I got the problem similar to this post here: https://rails.lighthouseapp.com/projects/8994/tickets/106-authenticity_token-appears-in-urls-after-ajax-get-request

I got the problem similar to this post here: https://rails.lighthouseapp.com/projects/8994/tickets/106-authenticity_token-appears-in-urls-after-ajax-get-request

routes.rb

  map.namespace(:admin,  :active_scaffold => true) do |admin|
    admin.resources :regions, :shallow => true do |region| 
      region.resources :birds, :collection => {:search => :get}
    end 
  end

view

  <%= javascript_tag %Q(
    #{remote_function(:update => 'bird_search', :url => search_admin_region_birds_path(@region.id), :method => :get)}
  ) %>

It displays url like: http://localhost:3000/admin/regions/7/birds/search?authenticity_token=F43BcQUM4z3bl7s21kL开发者_开发知识库ZQrqwGkuErF7C9jiNMKFTZTo%3D

which should be: http://localhost:3000/admin/regions/7/birds/search

Without this working my Ajax pagination won't work... help!


what version of rails are you using? that ticket says it was closed out, maybe you are on earlier version

http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001653 the example output does not have the auth token


Fixed this by using Javascript instead of using RJS.

Many times RJS methods aren't very dependable when your apps get more complicated, so take care there.

Anyway for this problem I changed the code to:

  <%= javascript_tag %Q(
    new Ajax.Updater('region_birds', '#{of_region_admin_region_birds_path(@region.id)}', {asynchronous:true, evalScripts:true, method:'get'});
  ) %>
0

精彩评论

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