views:

331

answers:

2

I have two roles in devise. The first is the admin and the second the normal user-role. Now I´d like to give these two groups in some cases same rights with before filters.

How does this work?

I have:

before_filter :authenticate_user!, :only => [:new, :create]
before_filter :authenticate_admin!, :only => [:new, :create, :edit, :update, :destroy]

But now only a user can :new and :create...the admin not.. What I have to do here?

Thanks, Mattherick

+1  A: 

I haven't yet used Devise personally, so this is only to point you in the right direction. It might not work exactly right.

before_filter :authenticate_user_or_admin, :only => [:new, :create]
before_filter :authenticate_admin!, :only => [:edit, :update, :destroy]

# ...

protected
  def authenticate_user_or_admin
    unless user_signed_in? or admin_signed_in?
      # Redirect somewhere else
    end
  end
rspeicher
thanks rspeicher! I thought about nearly the same, but now it works.
A: 

You might be interested in using Devise with CanCan for managing roles. Here is a detailed explanation about how to do it: http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/

Tony