0

上传控制器

def create
@upload = @order.uploads.build(params[:uploadtwo]) 
   respond_to do |format|
    if @upload.save
    format.html { redirect_to root_path, :notice => 'File was successfully uploaded.' }
    format.json { render :json => @upload, :status => :created, :location => @upload }
  else
    format.html { render :action => "new" }
    format.json { render :json => @upload.errors, :status => :unprocessable_entity }     
end

结尾

上传模型

belongs_to :order

订单模型

has_many :uploads

我收到错误 [NoMethodError in UploadtwosController#create],[未定义的方法 `uploads' for nil:NilClass]

有人知道我没有做什么吗?

4

1 回答 1

0

belongs_to :order在您的 Upload 模型中声明并不意味着@order它将在控制器中自动定义。也许你想要的是before_filter控制器中的一个设置@order

于 2013-01-19T19:03:21.743 回答