I've some authentication in Ruby (from this tutorial - this use gem "bcrypt-ruby", :require => "bcrypt"
and I need write authenticity_token into json file. How i can get it and create this file?
Update: I've written:
json.array!(@session) do |session|
json.extract! session, :csrf-token
json.url tag_url(session, format: :json)
end
But it doesn't work. I need write from html
<meta content="authenticity_token" name="csrf-param" /> <meta content="74Mhbpn9FF/tY/cgfuVmX7ribN4rOkkdUjSgbLNsces=" name="csrf-token" />
This value: 74Mhbpn9FF/tY/cgfuVmX7ribN4rOkkdUjSgbLNsces=
This is my 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