Ruby On Rails Classroom image

Neha  Jaggi / 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
Neha  Jaggi

Skills    Ruby On Rails

Qualifications :- High School - , College/University - Graphic Era Hill University, Dehradun, College/University - ,
Location :-Dehradun,Dehradun,UTTARAKHAND,India
Description:-

Experienced Software Developer with a demonstrated history of working in the Information Technology and services industry. Skilled in Web Technologies (Ruby on Rails, PostgreSQL, php, Laravel and AJAX). 


Explore
 

  Students (0)