0
上传控制器为无未定义的方法:NilClass
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在UploadtwosController#创建],[未定义的方法`上传'为零:NilClass]
有人知道我在做什么?
感谢您的快速响应。我将如何定义它?与轨道新,这是我的第一个应用程序。 –
在你的控制器的某个地方,你会想要一些类似于'before_filter {@order = Order.new(...)}'的东西。究竟应该用什么来代替'...',取决于你希望使用默认的'@ order'的数据。请参阅Rails指南中的“before_filter”以获取更多信息。 –
非常感谢,就此 –