user2784630
user2784630

Reputation: 806

How to get pass ApplicationController method for ActiveAdmin Devise's Admin User?

I'm using ActiveAdmin with Devise and have 2 models, User and AdminUser. Both models are apart of Devise when generated:

20140210105605_devise_create_users.rb

20140731015129_devise_create_admin_users.rb

The users table has 4 new columns which are :name, :latitude, :longitude, :address

Just in case in the initializers/devise.rb I added the following lines:

# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
config.scoped_views = true

# Configure the default scope given to Warden. By default it's the first
# devise role declared in your routes (usually :user).
config.default_scope = :user

I'm having trouble getting pass a method meant for my users only:

ApplicationController

before_filter :set_user_location

private

def set_user_location
  if user_signed_in?
    @user_location = current_user.address
    @user_latitude = current_user.latitude 
    @user_longitude = current_user.longitude
  end
end

This is throwing me this error:

undefined method `address' for nil:NilClass

But this method shouldn't even take place unless a User is signed in, not an AdminUser. How would I fixed this?

Upvotes: 0

Views: 873

Answers (1)

nistvan
nistvan

Reputation: 2970

Try this: before_filter :set_user_location, :if => proc { current_user }

In this case the filter will be applied only if the curren_user has been set.

Upvotes: 3

Related Questions