智能手机上已禁用Cookie的InvalidAuthenticityToken

时间:2012-09-25 18:36:03

标签: ruby-on-rails forms protect-from-forgery

使用Rails 3.0.3和Heroku

我的Heroku应用上的表单帖子出现了InvalidAuthenticityToken等错误。在我的应用程序控制器中,我启用了protect_from_forgery。

class ApplicationController < ActionController::Base
  protect_from_forgery
  ...
end

我的搜索表单

<%= form_tag(searchresults_url) do %>
  <%= text_field_tag :search_query, '', :size => 14 %> <%= submit_tag (t :search) %>
<% end %>

路线:

match 'searchresults' => 'home#searchresults', :as  => :searchresults

class HomeController < ApplicationController


  def searchresults

    @query = query_string
        @entries_found = Counter.where(...)     

  end


end

当有人尝试通过我的搜索表单搜索网站以及他们 Cookie已禁用并使用智能手机时,会发生无效的toke错误。我试图通过我的网络浏览器(Firefox)访问该网站,禁用了cookie,它运行正常。

我没有在我创建的“搜索引擎”上得到这种行为(我在这个应用程序中无法使用的方式)所以出了什么问题。为什么只禁用智能手机和cookie?

我可以做些什么来完成这项工作?

1 个答案:

答案 0 :(得分:0)

快速而肮脏的“解决方案”是添加

protect_from_forgery :only => [:create, :update, :destroy]

用于相关控制器。我不确定这给网站带来了什么风险......