未知属性Rails

时间:2015-03-18 17:35:36

标签: ruby-on-rails

我是Rails的新手,我正在努力让我的应用程序运行。

我的UserMigration.rb文件包含:

class UserMigration < ActiveRecord::Migration
def self.up

if (!ActiveRecord::Base.connection.table_exists? :users)
  drop_table :users

  create_table :users do |t|
    t.string :email
    t.string :first
    t.string :last
    t.string :password
    t.string :username
    t.integer :created_by

    t.string :bio #Newly added
    t.integer :id #Newly added
    t.string :photoURL #Newly added

  end
  add_index :users, :email
end
if (Models::Persistence::User.count == 0)
  Models::Persistence::User.create({:email => 'testuser@my.com',
                                    :username => 'testuser@my.com',
                                    :first => 'Test',
                                    :last => 'User',
                                    :password => 'Test123',
                                    :bio => "User, student",
                                    :id => "1",
                                    :photoURL => "http://link",
                                    :created_by => 1})

我的模型User.rb文件包含:

module Models
    module Persistence
      class User < ActiveRecord::Base
         validates :bio, :presence => true, length:  {minimum: 150}

我正在研究一个例子,我最近在users表中添加了三个额外的字段(bio,id和photoURL)。当我使用db上新添加的字段运行测试时,我不断收到此错误:

      undefined method `bio' for #<Models::Persistence::User:0x007f8c04ae6838>

关于我可以从哪里开始调试的指针?谢谢!

0 个答案:

没有答案