我收到以下错误:
未定义的方法`comments ='对
< ActionItem:0x0000010643cb80>
以下代码:
correspondence_controller.rb
class CorrespondenceController < ApplicationController
protect_from_forgery
def add
correspondence = ActionItem.new
correspondence.event_id = params[:event_id]
correspondence.comments = 'cccc' #gives error
correspondence.user_id = params[:user_id] ##gives error
if correspondence.save
render :json => { :status => :ok}
else
render :json => { :status => :fail}
end
end
end
correspondence.rb
class Correspondence < ActiveRecord::Base
end
迁移文件
class CreateCorespondences < ActiveRecord::Migration
def change
create_table :correspondences do |t|
t.integer :event_id
t.integer :user_id
t.text :comments
t.timestamps
end
end
end
答案 0 :(得分:1)
将correspondence = ActionItem.new
更改为correspondence = Correspondence.new
。