0
嘿,我正在创建数据库模式并在rails控制台中测试它。我有关系用户has_many:费率和费率belongs_to:用户。当我在轨控制台输入:未定义的方法`<<'为零:NilClass rail console
user = User.find(1)
rate = Rate.find(1)
user.rates << rate
每一件事工作正常,但是当我想这样做相反的方式:
user2 = User.find(2)
rate2 = Rate.find(2)
rate2.user << user2
我有一个下面的错误NoMethodError:未定义的方法` < <'的零:NilClass
用户迁移
class CreateUsers < ActiveRecord::Migration
def up
create_table :users do |t|
t.column "username", :string, :limit => 25
t.string "first_name", :limit => 30
t.string "last_name", :limit => 50
t.string "password"
t.date "date_of_birth"
t.timestamps
end
end
end
价格迁移
class CreateRates < ActiveRecord::Migration
def change
create_table :rates do |t|
t.integer "user_id"
t.integer "credibility", :limit => 1 #0 or 1
t.timestamps
end
add_index("rates", "user_id")
end
end
谢谢!问题解决了 – mkkrolik 2014-12-06 09:29:45