Ruby on Rails unknown attribute form error

Posted by Ulkmun on Stack Overflow See other posts from Stack Overflow or by Ulkmun
Published on 2010-12-26T16:47:28Z Indexed on 2010/12/26 16:54 UTC
Read the original article Hit count: 219

Filed under:
|

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'

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about forms