0

I need to access my current users role in order to make sure they are an admin. If they are an admin I want to display the following link in my view.

<% if current_user.role =='admin' %>
    <li class="manage">
        <a href="#" id="manage" style="float:none;">
            Manage
        </a>
    </li>
<% end %>

My problem is in the controller (below). How do I define @user so that it aligns with the current user? right now I am getting a "Couldn't find User without an ID" error

def index

@user = User.find(params[:id])
respond_to do |format|
  format.html 
end
icedwater
  • 4,701
  • 3
  • 35
  • 50
  • `@user = current_user`. But then why don't you skip `@user` and use `current_user` directly? – PinnyM May 02 '13 at 17:59

1 Answers1

0

Why do you want to align @user and current_user? They are two different things.

  • current_user is the user you are logged in as (identified and authenticated). Are you using devise or another authentication gem?
  • @user is typically the user you're trying to edit, or display, determined by params[:id]. Basically the resource you're trying to access. What begs the question; what does @user mean to you?
boulder
  • 3,256
  • 15
  • 21