0

我正在尝试将一个简单的表单放在一起,但是每当我将表单字段插入到 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
4

1 回答 1

1

通过查看错误,您的上传模型似乎没有名称属性。如果你添加了这个,也许你忘记了迁移你的数据库?

于 2012-05-17T14:53:55.283 回答