ruby - Rails , enum role -
create enum user model
class user < activerecord::base # include default devise modules. others available are: # :confirmable, :lockable, :timeoutable , :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable enum role: [:user, :manager] has_many :tickets end
and when sign_up user.manager error
undefined method `manager?' nil:nilclass
my views _header.html.haml
%div .navbar.navbar-fixed-top.navbar-inverse %ul -if user_signed_in? %li= link_to 'new ticket', new_ticket_path, class: 'btn btn-danger' %li= link_to 'log out', destroy_user_session_path, class: 'btn btn-primary', method: :delete -elsif current_user.manager? %li= link_to 'all tickets', '#' -else %li= link_to 'sign up', new_user_registration_path, class: 'btn btn-primary' %li= link_to 'log in', new_user_session_path, class: 'btn btn-primary'
-if user_signed_in? # skipped -elsif current_user.manager? # skipped
what write illogical, since current_user
defined, when user is signed in.
your elsif
invoked when no user is signed in, throw error, obviously, since calling method on nil
(no current_user
).
Comments
Post a Comment