2015-09-06 64 views
0

我在全新的Rails应用程序上使用Rails 4.2.1。 我一直当试图从控制台创建新的用户收到此错误:引发ArgumentError:您需要提供至少一个验证Rails 4.2.1:ArgumentError:您需要提供至少一个验证

我一直在谷歌上搜索兜了几个小时,但我坚持这一点。

这是我的命令从控制台的新用户:

User.create(:first_name => "John", :last_name => "Doe", :username => "John", :email => "[email protected]", :password => "password") 

这是我User型号:

class User < ActiveRecord::Base 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, 
     :validatable, :omniauthable, 
     :omniauth_providers => [:facebook] 

    has_many :answers 
    has_many :comments 
    has_many :polls 
    has_many :settings 
    has_many :stories 
    has_many :story_followers 

    validates :username, presence: true 
    validates :first_name, presence: true 
    validates :last_name, presence: true 
    validates :bio, length: { maximum: 300, too_long: "%{count} characters is the maximum allowed" } 

    has_attached_file :avatar, :styles => { 
          :large => "500x500#", 
          :medium => "250x250#", 
          :thumb => "100x100#" 
          }, :default_url => "avatarmissing.png" 

    validates_attachment_content_type :avatar, :content_type => %w(image/jpeg image/jpg image/png image/gif) 
end 

我在做什么错?

+0

您需要将bio属性添加到create语句中,我期望得到一个不同的错误消息。 – margo

+0

你能提供你收到的实际堆栈跟踪吗? –

+0

我解决了这个问题。由于错误,我忘了在另一个模型中添加“存在:真实”。 –

回答

0

我会首先评论一下你已有的验证,以帮助缩小问题的范围。该错误消息指向无效验证(包括回形针验证)。

此外,您可能需要在您的属性中指定:password_confirmation。

相关问题