Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Ruby and Rails

Session Management

Book navigation

  • Single line swapping in Ruby
  • Array Operations in Ruby
  • File operations in Ruby
  • User defined functions in Ruby
  • Classes and Objects in Ruby
  • Simple Form Hello Rails Application
  • Database Application using scaffold - [Video]
  • Session Management
  • Cookies Management in Ruby on Rails
  • File Uploads in Ruby on Rails
By Karthikeyan , 24 October, 2012

Sessions can be used to store data at server side between the multiple requests from the same client.

Exmple #1


In this example counter2 variable value is stored in session variable. It gets incremented on each request.

Controller


class LookController < ApplicationController
  def index
    at
    render :action=>"at"
  end
  def at
    @counter1=1
    if(session[:counter2])
      @counter2=session[:counter2]
      @counter2+=1
      session[:counter2]=@counter2
    else
      @counter2=1
      session[:counter2]=@counter2
    end
  end
end

Viewv


views\look\at.rhtml


<h1>Working with sessions</h1>
<% form_tag :action => "at" do %>
Counter 1 = <%=@counter1%>
<br/>
Counter 2 = <%=@counter2%>
<br/>
<%=submit_tag "submit" %>
<%end%>

Output


Working with sessions
Counter 1 = 1
Counter 2 = 6
  • Add new comment

Comments

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy