Ruby On Rails Classroom image

Pooja  Negi / Student / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3|Last
Lessons:-Deleting Users-Administrative Users

implies (via the RSpec boolean convention) that the user should have an admin? boolean method.

             As usual, we add the admin attribute with a migration, indicating the boolean type on the command line:

$ rails generate migration add admin to users admin:boolean

 

The migration simply adds the admin column to the users table (Listing 9.40), yielding the data model in Figure 9.13.  

 

 

Note that we’ve added the argument default: false to add_column in Listing 9.40, which means that users will not be administrators by default. (Without the default: false argument, admin will be nil by default, which is still false, so this step is not strictly necessary. It is more explicit, though, and communicates our intentions more clearly both to Rails and to readers of our code.)

             Finally, we migrate the development database and prepare the test database:

$ bundle exec rake db:migrate
$ bundle exec rake db:test:prepare

 

As expected, Rails figures out the boolean nature of the admin attribute and automatically adds the question-mark method admin?: 

$ rails console --sandbox
>> user = User.first
>> user.admin?
=> false

 

 

 
 
 
image
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
Explore
 

  Students (0)