lundi 16 mars 2015

How to set cookies in Ruby on Rails 3?

I want to store username and password in cookies.If due to some reason my page removed when i will type the URL and press enter the page will come which should come after login.I have used also session.Please help me to add cookies in my app.


I am working on the below code.



class SessionsController < ApplicationController
def loginuser
@users=User.authenticate(params[:users][:email], params[:users][:password])
if @users
session[:user_id]=@users.id
flash[:notice]="login successfull"
flash[:color]="valid"
redirect_to :action => 'member',:controller => 'homes'
else
flash[:notice]="could not Logged in"
flash[:color]="invalid"
render 'member', :controller => 'homes'
end
end
def removeuser
session[:user_id] = nil
flash[:notice]="user logged out successfully"
flash[:color]="valid"
redirect_to :action => 'member', :controller => 'homes'
end
end


Please help me to add cookies.


Aucun commentaire:

Enregistrer un commentaire