开发者

ruby on rails session information grab

When i run in my page this code :

<% user = User.find(session[:userid]) %>

i get the error :

line #1 raised:

Couldn't find User without an ID

although i have in my authentification in my sessions_controller this :

def create
    if user = User.authenticate(params[:username],params[:password])
      session[:user_id]= user.id
      session[:language_id]= user.language_id
      User.find(user.id).update_attributes(:last_login => Time.now)
      redirect_to root_path 开发者_运维技巧, :notice => (I18n.t :"session.login_success")
    else
      flash.now[:alert] = (I18n.t :"session.error")
      render :action => 'new'
    end
  end

and the session should contain the userid


In your log-in you set session[:user_id], and you try to find session[:userid] (note the spurious underscore). That's why.


Your controller is looking for params session[:user_id], but in your views it is session[:userid] so it will complain that session[:user_id] is nil.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜