Ruby On Rails Classroom image

Pooja  Negi / Student / Web Technology

To post your Question Join Classroom
Lesson Topics's No:-  |1 | 2|Last
Lessons:- A Working sign in Method

  A Working sign in Method

Now we’re ready to write the first signin element, the sign_in function itself. As noted above, our desired authentication method is to place a remember token as a cookie on the user’s browser, and then use the token to find the user record in the database as the user moves from page to page (implemented in Section 8.2.3). The result, Listing 8.19, introduces two new ideas: the cookies hash and current_user



Listing 8.19 introduces the cookies utility supplied by Rails. We can use cookies as if it were a hash; each element in the cookie is itself a hash of two elements, a value and an optional expires date. For example, we could implement user signin by placing a cookie with value equal to the user’s remember token that expires 20 years from now:

cookies  [:remember token] =   {  value: user.remember token,
                                      expires: 20.years.from now.utc }


(This uses one of the convenient Rails time helpers, as discussed in Box 8.1.)

Pooja   Negi

Skills    Ruby On Rails

Qualifications :- High School - SSN high school, College/University - HNBGU, College/University - SRHU,
Location :-Ranipokhari,Rishikesh,Uttarakhand,India
Description:- Student

  Students (0)