【问题标题】:remote_function keeps adding authenticity token on GET requestsremote_function 不断在 GET 请求上添加真实性令牌
【发布时间】:2010-04-16 21:11:57
【问题描述】:

我在这里遇到了与此帖子类似的问题: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

查看

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

它显示的网址如下: http://localhost:3000/admin/regions/7/birds/search?authenticity_token=F43BcQUM4z3bl7s21kLZQrqwGkuErF7C9jiNMKFTZTo%3D

应该是: http://localhost:3000/admin/regions/7/birds/search

如果没有这个工作,我的 Ajax 分页将无法工作...帮助!

【问题讨论】:

    标签: ruby-on-rails ajax routing


    【解决方案1】:

    您使用的是什么版本的导轨? 那张票说它被关闭了,也许你在早期版本中

    http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001653 示例输出没有身份验证令牌

    【讨论】:

    • 我正在使用最新的 2.3.5 版本 想知道这是否是 Rails 错误?
    【解决方案2】:

    通过使用 Javascript 而不是使用 RJS 解决了这个问题。

    很多时候,当您的应用变得更复杂时,RJS 方法并不是很可靠,所以要小心。

    无论如何,对于这个问题,我将代码更改为:

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

    【讨论】:

      猜你喜欢
      • 2011-03-09
      • 2011-05-05
      • 1970-01-01
      • 2014-07-05
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      • 2019-12-06
      相关资源
      最近更新 更多