Forum: Ruby on Rails trouble with file_column plugin

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Roberto S. (Guest)
on 2005-11-15 00:05
(Received via mailing list)
I can't get the file_column plugin 0.3 working propperly (on Win XP,
rails 0.14.3) . Without validation and form redisplay, everythings seems
work fine, by when I do a form redisplay, then the file-column field is
after saving the record, however i have in the hidden formfield the key
the already uploaded file a temporary location. Here are the relevant
snippets of my code:

# Model
class Book < ActiveRecord::Base
belongs_to :user
file_column :file
validates_presence_of :title, :amount
validates_numericality_of :amount

# Controller
def create_ebook
return unless
uploaded_file = params[:book][:file]

@book = => uploaded_file,
:size => uploaded_file.size,
:title => params[:book][:title],
:amount => params[:book][:amount],
:created_at =>

current_user.books << @book
if @ebook.file.nil?
flash[:notice] = "#{@book['file']} upload failed"
flash[:notice] = "#{@book['file']} uploaded successfully"
redirect_to :action => 'list'
@user = current_user

# View
<%= form_tag( { :action => "create_book" }, { :multipart => true } ) %>
<%= error_messages_for 'book' %>
<label for="upload_filename">File: </label><br/>
<%= file_column_field("book", "file") %><br/><br/>
<label for="title">Title</label><br/>
<%= text_field 'book', 'title' %><br/><br/>
<label for="amount">Price in U$</label><br/>
<%= text_field 'book', 'amount' %><br/><br/>
<%= submit_tag 'Upload' -%>
<%= end_form_tag %>

Has anybody an idea what I am doing wrong or has a working example of
file-column code to share ?

thanks in advance
skanthak (Guest)
on 2005-11-15 12:28
(Received via mailing list)
On 11/14/05, R. Saccon <removed_email_address@domain.invalid> wrote:
>   belongs_to :user
>     uploaded_file = params[:book][:file]
>     @book = => uploaded_file,
>                       :size => uploaded_file.size,
>                       :title => params[:book][:title],
>                       :amount => params[:book][:amount],
>                       :created_at =>

well, you aren't passing the hidden field (which is called
'book[file_temp]') to the book model. The shortest way would be
something like: "@book =[:book])" as it will
automatically include all params, but you might have to be careful
about security in this case.

If you want to keep your current style, you should add the following
after creating the @book object:

   @book.file_temp = @params[:book][:file_temp] if

Hope this helps
This topic is locked and can not be replied to.