is_admin? function in rails? - undefined method Error

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-05-04T08:58:25Z Indexed on 2010/05/04 9:28 UTC
Read the original article Hit count: 195

Filed under:

Hello! At the moment, I am creating some kind of admin panel/backend for my site. I want to do the following: Only admins (a user has a user_role(integer) --> 1 = admin, 2 = moderator, 3 = user) can see and access a link for the admin panel. So I created an admin_controller. In my admin controller I created a new function called is_admin?:

class AdminController < ApplicationController

  def admin_panel
  end

  def is_admin?
    current_user.user_role == 1
  end

end

my route looks like.

map.admin_panel '/admin-panel', :controller => 'admin', :action => 'admin_panel'

and in my _sidebar.html.erb (partial in applicaton.html.erb) I created the link:

<%= link_to "Admin Panel", :admin_panel unless is_admin? %>

Now I get an error called:

undefined method `is_admin?'

Where is the problem? Please help me solving this problem!

© Stack Overflow or respective owner

Related posts about ruby-on-rails