Hai!

I have two controller. the one is first_controller and another one is
second_controller.

first_controller.rb

def login
.
.
if @user && @user.password == params[:user][:password]
session[:user_id] = @user.id
redirect_to :controller => "second_controller", :action => "index"
end
end

second_controller.rb

def index
if session[:user_id] != nil
logger.info" The user id is not null"
else
logger.info" The user id is null"
end
end

#=======Result
The user id is not null # 1st time
The user id is null # 2nd time
The user id is not null # 3rd time
The user id is not null # 4th time
The user id is null # 5th time
The user id is not null # 6th time
The user id is not null # 7th time
The user id is not null # 8th time
The user id is not null # 9th time
The user id is not null # 10th time
The user id is not null # 11th time
The user id is null # 12th time

Here my session variable id dynamic not a static. But i want static
value.
I hope this is session problem. help me.

Thanks for you.
bdeveloper01

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Bala TS at Jan 23, 2012 at 11:03 am
    Hai!

    I tried

    session[:user_id].freeze

    but I got same problem


    At-last I got one solution.

    def login
    .
    .
    if @user && @user.password == params[:user][:password]
    session[:user_info_id] = session[:user_id] = @user.id
    session[:user_info_id].freeze
    redirect_to :controller => "second_controller", :action => "index"
    end
    end

    second_controller.rb

    def index
    if session[:user_info_id] != nil
    session[:user_id] = session[:user_info_id]
    logger.info" The user id is not null"
    else
    logger.info" The user id is null"
    end
    end

    ===========>result

    The user id is not null
    The user id is not null
    The user id is not null
    The user id is not null
    The user id is not null
    The user id is not null
    The user id is not null
    The user id is not null
    The user id is not null
    The user id is not null
    The user id is not null
    The user id is not null

    Thanks for ruby-forum
    by:
    bdeveloper01

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to [email protected].
    To unsubscribe from this group, send email to [email protected].
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 23, '12 at 4:32a
activeJan 23, '12 at 11:03a
posts2
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Bala TS: 2 posts

People

Translate

site design / logo © 2023 Grokbase