Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 views
in Technique[技术] by (71.8m points)

accessing admin attribute and admin? method in ruby on rails

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...