views:

148

answers:

1

I have this ruby function in a controller

def updateSession value
   case value
   when 1,2
     session[:value]=1
   when 3,4
     session[:value]=2
   end
end

And I have different links that redirect to different pages. I would like to change the session value when clicking on those links by calling the updateSession function

Is it possible and if so, how?

A: 

You could add a route for:

map.update_session 'update_session', :controller => "session", :action => "update"

Then I assume you're trying to get "value" from user parameters, so you could use the following to generate your links:

<%= link_to "Update Session - 1", update_session_path(:value => 1) %>

Then add the following to your controller to act based on the params provided:

def update_session
  value = params[:value].to_i
  case value
  when 1,2
    session[:value] = 1
  when 3,4
    session[:value] = 2
  end
end
bensie
ty that works fine, but is there a way to hide the url in the status and address bar. Cause when the user put his mouse over the link he can see the address, copy/paste it and change the parameter value. I would like to avoid that.
Mathieu