加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用link_to Rails设置会话变量

发布时间:2020-12-17 02:44:09 所属栏目:百科 来源:网络整理
导读:是否可以使用link_to设置会话变量?我不想设置参数,因为我有一些重定向并且它被擦掉了. 即我想用链接将会话变量“modelid”设置为“you”. 我想在FB登录oauth运行时设置会话变量… %= link_to "New Post","#",{:class = "btn btn-primary btn-large inline p
是否可以使用link_to设置会话变量?我不想设置参数,因为我有一些重定向并且它被擦掉了.

即我想用链接将会话变量“modelid”设置为“you”.

我想在FB登录oauth运行时设置会话变量…

<%= link_to "New Post","#",{:class => "btn btn-primary btn-large inline pull-left",:onclick => "FB.login(function(response){},{perms:'email,publish_stream,user_photos'});" } %>

解决方法

您可以在其中一个控制器中创建一个设置此会话变量的操作,然后使用AJAX请求调用它.

路线:

post "/myroute",:to=>"some_controller#set_my_session_var"

some_view.html.erb(jquery示例):

$(function(){
  $("#my-button").click(function(){
    $.post('/myroute');
  })
})

some_controller.rb:

def set_my_session_var
  session[:somekey]='somevalue'
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读