我是rails的初學者。我想要做的是製作一個只有標題和內容的表格,並建立一個可以保存它們的數據庫。軌道上紅寶石沒有方法錯誤
這是我的遷移文件
class CreateMelons < ActiveRecord::Migration
def change
create_table :melons do |t|
t.string :title
t.text :content
t.timestamps null: false
end
end
end
這是我的控制器
def write
@title =params[:title]
@content = params[:content]
@new_post = Melon.new
@new_post.title =params[:title]
@new_post.content =params[:content]
@new_post.save
redirect_to "/list"
end
和錯誤信息都在這裏。
undefined method `title=' for #<Melon id: nil, created_at: nil, updated_at: nil>
我不知道是什麼原因。 有標題欄! 我執行了rake db:migrate命令。 請幫幫我!
你可以顯示你的melon.rb模型的文本嗎? – moveson
您沒有此模型的標題'#
您是否更新了相同的遷移或是否曾遷移過它 –