我正在尝试将一个简单的表单放在一起,但是每当我将表单字段插入到 html 中时,我都会不断收到 no method 错误。
这里有什么问题?
错误:
undefined method `name' for #<Upload id: nil, created_at: nil, updated_at: nil>
新的.html.erb
<h1>Uploads#new</h1>
<p>Find me in app/views/uploads/new.html.erb</p>
<% form_for :upload, :url => uploads_path do |f| %>
<p>
Name: <%= f.text_field :name %>
</p>
<p><%= submit_tag "Create Upload" %></p>
<% end %>
上传.rb
class Upload < ActiveRecord::Base
has_many :tasks
end
uploads_controller.rb
class UploadsController < ApplicationController
def index
@uploads = Upload.find(:all)
end
def new
@upload = Upload.new
end
def create
@upload = Upload.new(params[:project])
if @upload.save
flash[:notice] = "Film successfully uploaded"
redirect_to uploads_path
else
render :action => 'new'
end
end
end