Set Session Variable Using Link_to Rails

Is it possible to set a session variable using link_to? I do not want to set the parameter, because I have several redirects, and it is removed.

i.e. I want to set the "modelid" session variable to "you" with a link.

I want to set a session variable while FB login oauth is working ...

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

You can create an action in one of your controllers that sets this session variable and then calls it using an AJAX request.

routes:

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

some_view.html.erb (jquery example):

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

some_controller.rb:

 def set_my_session_var session[:somekey]='somevalue' end 
+7
source

All Articles