Q:

Instance variable in controllers

When I define an instance variable in an action, is it not available inside other actions belonging to same controller.
Instance variable should be available throughout the class. Right?
    class DemoController < ApplicationController

  def index
    #render('demo/hello')
    #redirect_to(:action => 'other_hello')

  end

  def hello
    #redirect_to('http://www.google.co.in')
    @array = [1,2,3,4,5]
    @page = params[:page].to_i
  end

  def other_hello
    render(:text => 'Hello Everyone')
  end

end

If I define the array in index and access it from hello view then why am I getting errors for false values of nil?

A:

The instance variables are available only during the request (controller and view rendering), because Rails create a new instance of controller for each request.
If you want to keep data between request, use sessions.

