【发布时间】:2017-01-20 02:19:24
【问题描述】:
我正在尝试在我的应用程序的 rails 控制台中初始化一个新用户。每当我输入初始化代码时:
irb(main):001:0> user = User.new
我得到这个错误:
(Object doesn't support #inspect)
=>
irb(main):002:0>
我已正确设置了用户凭据,并且没有以错误的方式使用任何代码。
class User
include Mongoid::Document
# User fields
field :first_name, type: String
field :last_name, type: String
field :phone_number, type: Integer
field :address, type: String
field :info, type: String
field :portfolio, type: String
field :motto, type: String
field :cover, type: BSON::Binary
field :avatar, type: BSON::Binary
field :photo, type: BSON::Binary
field :request, type: Boolean
field :decision, type: Boolean
field :gender, type: String
field :user_url, type: Mongoid::EncryptedHash
field :position, type: String
field :created_at, type: DateTime, default: ->{DateTime.now}
field :updated_at, type: DateTime
field :view_comments_count, type: Integer
field :thumbs_up_notifications, type: Boolean
field :tracking_notifications, type: Boolean
field :message_notifications, type: Boolean
field :applaud_notifications, type: Boolean
field :shout_out_notifications, type: Boolean
field :congrats_notifications, type: Boolean
field :post_notifications, type: Boolean
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
## Database authenticatable
field :email, type: String, default: ""
field :password, type: Mongoid::EncryptedString, default: ""
## Recoverable
field :reset_password_token, type: Mongoid::EncryptedString
field :reset_password_sent_at, type: Time
## Rememberable
field :remember_created_at, type: Time
## Trackable
field :sign_in_count, type: Integer, default: 0
field :current_sign_in_at, type: Time
field :last_sign_in_at, type: Time
field :current_sign_in_ip, type: String
field :last_sign_in_ip, type: String
## Confirmable
field :confirmation_token, type: String
field :confirmed_at, type: Time
field :confirmation_sent_at, type: Time
field :unconfirmed_email, type: String # Only if using reconfirmable
## Lockable
field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
field :unlock_token, type: String # Only if unlock strategy is :email or :both
field :locked_at, type: Time
attr_accessor :verify_password, :password_confirmation
attr_reader :comment_notifications, :post_notifications,
:shout_out_notifications, :thumbs_up_notifications,
:applaud_notifications, :tracking_notifications,
:congrats_notifications, :message_notifications,
:request_notifications, :acceptance_notifications
validates :first_name, presence: true
validates :last_name, presence: true
validates :email, presence: true
validates :password, presence: true
validates :phone_number, presence: true
validates :address, presence: true
validates :info, presence: true
validates :motto, presence: true
validates :gender, presence: true
validates_confirmation_of :password
has_many :posts
has_many :comments
has_many :thumbs_ups
has_many :congrats
has_many :tracks
has_many :shout_outs
has_many :applauds
has_many :assignments
has_one :position
has_one :rank
belongs_to :group
after_create :find_default_contacts, :create_url
before_save :validates_email, :validates_motto, :validates_info
如果有人能指出导致错误的原因,我将不胜感激。
【问题讨论】:
-
你能给我看看你的用户迁移文件吗?只需从架构中复制和粘贴?
-
我正在使用 NoSQL 数据库:MongoDB。没有迁移。
-
你能粘贴完整的 user.rb 代码和你的 gemfile 吗?
-
能否请您粘贴您的
User模型我认为您正在覆盖initialize方法如果是,那么您应该在您的initialize方法上调用super -
实际上没有初始化方法。这可能是错误一直显示的原因吗?
标签: ruby-on-rails irb rails-console