Ruby On Rails Classroom image

Anil  Bist / Professional / 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
Anil  Bist

Skills    Ruby On Rails

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)