Sessions can be used to store data at server side between the multiple requests from the same client.
In this example counter2 variable value is stored in session variable. It gets incremented on each request.
class LookController < ApplicationController def index at render :action=>"at" end def at @counter1=1 if(session[:counter2]) @counter2=session[:counter2] @counter2+=1 session[:counter2][email protected] else @counter2=1 session[:counter2][email protected] end end end
<h1>Working with sessions</h1> <% form_tag :action => "at" do %> Counter 1 = <%[email protected]%> <br/> Counter 2 = <%[email protected]%> <br/> <%=submit_tag "submit" %> <%end%>
Working with sessions Counter 1 = 1 Counter 2 = 6