Ruby on Rails unknown attribute form error
- by Ulkmun
I'm attempting to create a form which will allow me to upload a file.. I've got the following form..
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :body %><br />
<%= f.text_area :body, "cols" => 100, "rows" => 40 %>
</div>
<div class="field">
<%= f.label :upload %><br />
<%= f.file_field :upload %>
</div>
<div class="actions">
<%= f.submit %>
</div>
I've got a controller which seems to error in this function..
# POST /posts
# POST /posts.xml
def create
@post = Post.new(params[:post])
@post = DataFile.save(params[:upload])
##render :text => "File has been uploaded successfully"
respond_to do |format|
if @post.save
format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
format.xml { render :xml => @post, :status => :created, :location => @post }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
end
That's the method that get's called when I create the post.
The error is unknown attribute: upload
app/controllers/posts_controller.rb:42:in ``new'
app/controllers/posts_controller.rb:42:in ``create'