Iam trying to access the admin? method which was generated when I added the admin attribute to my database . Iam trying to use it in my _header partial to display a different navbar for admin users.
Iam requiring the User class in the application controller so that I may use its methods across my rails app as such
'''
require User
'''
I have also tried to wrap my user class in module named UserMod
and require it in application controller as well
'''
require UserMod
'''
yet when I try to us it in my header partial : app/views/layouts/_header.html.erb
```
<% if current_user && current_user.admin? %>
<li><%= link_to "Users", users_path %></li>
<%end%>
```
it produces the error :
'''
uninitialized constant
'''
when I do not require or include any classes or modules in the application controller it says that admin? method is not recognized.
Can anyone please assist me expand the scope of the the admin? method across my application.
Thank you so much!
question from:
https://stackoverflow.com/questions/65910757/accessing-admin-attribute-and-admin-method-in-ruby-on-rails 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…