I wanted to add a new Boolean attribute to my user: is_student
My project has 2 types of users: students & faculty. If is was a student is_student should be true and if it is faculty is_student would be false.
To add this new param I wrote this code in UsersController:
def user_params
params[:user].permit(:email, :password, :is_student)
end
And I wrote this code in routes.rb to have it overwritten:
resources :users, controller: :users, only: :create
as was shown in this stack overflow example: rails 4 and thoughtbot/clearance - adding fields to the user model
This is my user.rb class to add my new attribute "is_student":
class User < ActiveRecord::Base
include Clearance::User
@is_student = true
def is_student?
return @is_student
end
end
Right now, I have it set to true just to see that it works and it currently does not. I can see that it does not work because when I run my rails app I have this as my main page:
<% if signed_in? %>
<% if current_user.is_student? %>
<p> signed in and is student </p>
<% end %>
<p> signed in but not student </p>
<% else %>
<p> not signed in </p>
<% end %>
From this code: I am seeing "signed in but not student" even though is_student should be defaulted to true. Can anyone tell me what I have done wrong?