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」以獲取更多信息。 –
非常感謝,就此 –