【问题标题】:Why is Rails unpermitting its own automatically set parameters?为什么 Rails 不允许自己自动设置参数?
【发布时间】:2017-10-01 06:36:48
【问题描述】:

我的登录刚刚坏了。到目前为止它工作得很好,但现在我得到:“不允许的参数”。

Started POST "/login" for ::1 at 2017-09-30 20:29:47 +0200
Processing by SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"nDc9mpnsSvQSvHqACAgKteUi/ekfofao5sI9fe67iWaKikZul+mkKfRlkHtYiQtP71DrEmEZZtNnwlkXTvlNAg==", "username"=>"bjelline", "password"=>"[FILTERED]", "commit"=>"Log In"}
Unpermitted parameters: :utf8, :authenticity_token, :commit

我没有设置这些参数 utf8、authenticity_token 和 commit。所以我认为这是 rails 自动完成的。

为什么 Rails 不允许它自己设置的参数?

【问题讨论】:

    标签: ruby-on-rails strong-parameters


    【解决方案1】:

    发现问题:

    class ApplicationController < ActionController::Base
      protect_from_forgery with: :exception   # this was missing
    

    我错误地删除了“protect_from_forgery”。 这是 rails 的一部分,它会自动设置和检查 真实性_令牌。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多