我正在尝试将一个简单的表单放在一起,但每当我在html中插入一个表单字段时,我都会收到一个no method错误。
这里有什么问题?
错误:
undefined method `name' for #<Upload id: nil, created_at: nil, updated_at: nil>
new.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 %>
upload.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
答案 0 :(得分:1)
通过查看错误,您的上传模型似乎没有名称属性。如果您已经添加了这个,那么您可能忘记了迁移数据库了吗?