- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
"bcrypt" 并且我需要将 authenticity_tok-6ren">
我在 Ruby 中进行了一些身份验证(来自 tutorial - 这使用 gem "bcrypt-ruby", :require => "bcrypt"
并且我需要将 authenticity_token 写入 json 文件。如何我可以得到它并创建这个文件吗?
更新:我写过:
json.array!(@session) do |session|
json.extract! session, :csrf-token
json.url tag_url(session, format: :json)
end
但它不起作用。我需要从 html 写
<meta content="authenticity_token" name="csrf-param" /> <meta content="74Mhbpn9FF/tY/cgfuVmX7ribN4rOkkdUjSgbLNsces=" name="csrf-token" />
这个值:74Mhbpn9FF/tY/cgfuVmX7ribN4rOkkdUjSgbLNsces=
这是我的 session Controller :
class SessionsController < ApplicationController
def new
end
def index
@session
end
def create
user = User.authenticate(params[:email], params[:password])
if user
session[:user_id] = user.id
redirect_to root_url, :notice => "Logged in!"
else
flash.now.alert = "Invalid email or password"
render "new"
end
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "Logged out!"
end
end
最佳答案
有一个名为 form_authenticity_token
的 View 助手,它可以像这样访问或分配 token
def form_authenticity_token
session[:_csrf_token] ||= SecureRandom.base64(32)
end
要在 Controller 中获取它,请使用 session[:_csrf_token]
关于ruby-on-rails - 从 Rails 获取 authenticity_token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22821368/
我正在开发一个与 Rails 服务器通信的 Android 应用程序。我不想忽略 authenticity_token,但我也不认为要求它是正确的答案。可以采取哪些措施来保护我的 POST 请求? 最
什么情况下 form_authenticity_token 与 params[:authenticity_token] 不匹配? 我看到未经验证的请求进入我的应用程序,所以我覆盖了 form_tag
我在 Ruby 中进行了一些身份验证(来自 tutorial - 这使用 gem "bcrypt-ruby", :require => "bcrypt" 并且我需要将 authenticity_tok
我正在尝试将 Uploadify 与我的 Rails 3.1 应用程序一起使用,我已经完成了所有步骤(中间件、初始化程序、配置...等),我认为它们都运行良好,但一方面,我的真实性 token 正在过
我在用户管理 Controller 中有这样的更新方法 def update @user.update(user_permitted_params) redirect_to admin_use
如何从 Ruby on Rails 中的 authenticity_token 中删除 div? 谢谢。 最佳答案 您可以使用 form_authenticity_token 来解决这个问题,因为我相
我用这个把我的头发扯掉了。我在带有嵌套资源的 form_with 上得到了一个未经许可的参数。我正在使用 Rails 5.2.1 和 Ruby 2.5。 我不确定我到底哪里出了问题。我尝试了 site
我正在提交一个简单的 ajax 删除请求,如下所示: #invitation_actions =link_to "delete", invitation_path(invitation), :me
我是一名优秀的程序员,十分优秀!