在Activeadmin中查看用户

时间:2013-09-29 13:17:03

标签: ruby-on-rails devise activeadmin

我正在尝试查看activeadmin面板中的所有用户但仍然遇到此错误:

NameError - uninitialized constant User::Profile:

我正在使用Devise。

这是我的user.rb:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable



  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  devise :omniauthable, :omniauth_providers => [:facebook]
  has_many :activities, :dependent => :destroy
  has_many :userinterests, :dependent => :destroy
  has_one :profile, :dependent => :destroy
  accepts_nested_attributes_for :userinterests, 
                                    :allow_destroy => true

  # Setup accessible (or protected) attributes for your model
  attr_accessible :username, :location, :dob, :age, :sex, :status, :about, :web, :email, :password, :password_confirmation, :time_zone, :avatar,  :userinterests_attributes
  attr_accessible :longitude, :latitude
  attr_accessible :provider, :uid, :name

  attr_accessible :body, :conversation_id
  geocoded_by :location
  mount_uploader :avatar, AvatarUploader
   acts_as_messageable
     acts_as_followable
     acts_as_follower

  after_validation :geocode, :if => :location_changed?
  def age
      now = Time.now.utc.to_date
      if dob 
      now.year - self.dob.year - ((now.month > self.dob.month || (now.month == self.dob.month && now.day >= self.dob.day)) ? 0 : 1)
    else
    end
  end

  def name
     username
   end

   def mailboxer_email(object)
     #Check if an email should be sent for that object
     #if true
     return "define_email@on_your.model"
     #if false
     #return nil
   end

   def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
     user = User.where(:provider => auth.provider, :uid => auth.uid).first
     unless user
       user = User.create(name:auth.extra.raw_info.name,
                            provider:auth.provider,
                            uid:auth.uid,
                            email:auth.info.email,
                            password:Devise.friendly_token[0,20]
                            )
     end
     user
   end

   def self.new_with_session(params, session)
       super.tap do |user|
         if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
           user.email = data["email"] if user.email.blank?
         end
       end
     end

end

这是我的admin / user.rb

ActiveAdmin.register User do

end

active_admin.rb

    ActiveAdmin.setup do |config|

  config.site_title = "Woo"
  config.authentication_method = :authenticate_admin_user!
  config.current_user_method = :current_admin_user
  config.logout_link_path = :destroy_admin_user_session_path
  config.batch_actions = true

end

无论我编辑什么,我都会出现名称错误。 欢迎提出任何建议:)

1 个答案:

答案 0 :(得分:1)

我将此添加到我的admin / User.rb并且它有效。

 module MetaSearch
      class Builder
          def matches_attribute_method(method_id)
              method_name = preferred_method_name(method_id)
              where = Where.new(method_id) rescue nil
              return nil unless method_name && where
              match = method_name.match("^(.*)_(#{where.name})=?$")
              if match
                  attribute, predicate = match.captures
                  attributes = attribute.split(/_or_/)
                  if attributes.all? {|a| where.types.include?(column_type(a))}
                      return match
                  end
              end
              nil
          end
      end
      module Utility
          private
          def preferred_method_name(method_id)
              method_name = method_id.to_s
              where = Where.new(method_name) rescue nil
              return nil unless where
              where.aliases.each do |a|
                  break if method_name.sub!(/_#{a}(=?)$/, "_#{where.name}\\1")
              end
              method_name
          end
      end
  end