Rails authentication issue -
i relatively new rails , right developing simple log in log out system.
in app when log in url generated is:
localhost:3000/user/index/7
when log out root. if copy url , paste in browser window instantly logged in without being directed log in form. how correct issue.
i tried store user id in session hash , upon logout have set user id in session nil. not work. needed.
edited:
in home controller
class homecontroller < applicationcontroller def signin user=user.find(:all,:conditions=>["user_login=? , user_password=?",params[:user] [:username],params[:user][:password]); if user!=nil session[:user_id]=user.user_id; redirect_to({:controller=>'user'}) end end end in user controller have logout method:
def logout session[:user_id]=nil; redirect_to({:controller=>'home'}); end my routes.rb file looks this:
actioncontroller::routing::routes.draw |map| map.root :controller => "home",:action => "index" map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end edited:
i have solved issue not checking id value in session hash in user controller index method. have question if have app in rails 2.3.17 , want shift latest version how changes have make
you can set before_filter actions in controller. using before_filter can check session nil or value present.
otherwise can follow railscasts video
http://railscasts.com/episodes/250-authentication-from-scratch
Comments
Post a Comment