无法在 ruby on rails 控制器中设置/使用会话变量
问题描述:
谁能告诉我在 ruby on rails 应用程序中从头开始设置/使用会话变量的正确方法.我无法在两个页面之间的控制器中设置/使用会话变量.我正在使用 CookieStore 会话类型.这是用于设置和获取会话变量的语法:
Can somebody tell me the right way to set/use session variables in a ruby on rails application from scratch. I am not able to set/use a session variable in my controller between two pages. I am using CookieStore session type. This is the syntax being used to set and get session variables:
session[:test] = "testing"
@test_str = session[:test]
如果我遗漏了什么,请告诉我.
Let me know in case I am missing on something.
这是我的控制器的样子:
This is how my controller looks like:
class PaymentsController < ApplicationController
# GET /merchant_test
def merchant_test
session[:test] = "testing"
render :layout => false
end
# POST /post_to_mobikwik
def post_to_mobikwik
zr = Mobikwik::Request.new(params)
@mobikwik_data = zr.all_params
@test_str = session[:test]
render :layout => false
end
# POST /z_response
def z_response
zr = Mobikwik::Response.new(request.raw_post)
@checksum_check = zr.valid?
@mobikwik_post = zr.all_params
@statuscode = @mobikwik_post['statuscode']
@statusmessage = @mobikwik_post['statusmessage']
if @statuscode == "0"
@verified = zr.verified?
else
@verified = false
end
render :layout => false
end
答
在 config/initializers/session_store.rb
AppName::Application.config.session_store :cookie_store, key: '_app-name_session'