2014-10-28 41 views
0

我收到以下錯誤:未定義<fieldname>錯誤ActionItem

undefined method `comments=' for

<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 

回答

1

變化correspondence = ActionItem.newcorrespondence = Correspondence.new