ruby-on-rails
2013-07-14 22 views 1 likes 
1

下面是完整的錯誤:創建新列,但我仍然得到NoM​​ethodError /未定義的方法

 Failure/Error: project = Factory.create(:question, :title => "How much does a wood chuck?") 
     NoMethodError: 
     undefined method `title=' for #<Question:0x007fe38caad1c0> 
     # ./spec/integration/creating_questions_spec.rb:15:in `block (2 levels) in <top (required)>' 

我創建了一個名爲「標題」新列這樣做:

rails generate migration AddTitleToQuestions title:string 

然後我遷移DB。這是我的schema.rb

 ActiveRecord::Schema.define(:version => 20130714164611) do 

     create_table "questions", :force => true do |t| 
     t.string "post" 
     t.datetime "created_at", :null => false 
     t.datetime "updated_at", :null => false 
     t.string "title" 
     end 
    end 

在我的模型:

class Question < ActiveRecord::Base 
     attr_accessible :post 
    end 

我嘗試添加「標題」我的模型,看它是否修復它,但我仍然得到同樣的錯誤。有任何想法嗎。

修復它: 我最終做了一個硬重置到以前的提交併再次創建新列。它現在起作用了,我不知道以前有什麼錯。

回答

1

嘗試運行rake db:test:準備並查看它是否有效。

+0

沒有,但它沒有奏效。 – Andy

相關問題