2014-08-27 105 views
-4

我想將數據添加到用戶模型中的買方和控制檯顯示錯誤ROR控制檯顯示語法錯誤

SyntaxError: (irb):6: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' 
...werty", password_confirmation "qwertyqwerty") 
...        ^
(irb):6: syntax error, unexpected ')', expecting end-of-input 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands/console.rb:47:in `start' 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands/console.rb:8:in `start' 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands.rb:41:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

寫在這裏是什麼

u = User.create(login: "weare138", email: "[email protected]", password: "qwertyqwerty", password_confirmation "qwertyqwerty") 

我的用戶模型

class User < ActiveRecord::Base 

#devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable 

    attr_accessible :login, :email, :password, :password_confirmation, :remember_me 

    has_one :cart 
    has_many :orders 
end 

怎麼修?

好吧,更正,但仍然

ActiveRecord::UnknownAttributeError: unknown attribute: email 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.19/lib/active_record/attribute_assignment.rb:88:in `block in assign_attributes' 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.19/lib/active_record/attribute_assignment.rb:78:in `each' 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.19/lib/active_record/attribute_assignment.rb:78:in `assign_attributes' 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.19/lib/active_record/base.rb:498:in `initialize' 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.19/lib/active_record/persistence.rb:44:in `new' 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/activerecord-3.2.19/lib/active_record/persistence.rb:44:in `create' 
    from (irb):8 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands/console.rb:47:in `start' 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands/console.rb:8:in `start' 
    from /home/weare138/.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands.rb:41:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

回答

3

你之後缺少冒號(:password_confirmation

u = User.create(login: "weare138", email: "[email protected]", password: "qwertyqwerty", password_confirmation: "qwertyqwerty")