ROR控制台显示语法错误

时间:2014-08-27 18:55:48

标签: ruby-on-rails

我想在用户模型中向买方添加数据,而控制台显示错误

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: "readfuzza@gmail.com", 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>'

1 个答案:

答案 0 :(得分:3)

您在:

之后缺少冒号(password_confirmation
u = User.create( login: "weare138", email: "readfuzza@gmail.com", password: "qwertyqwerty", password_confirmation: "qwertyqwerty" )