I can''t get the file_column plugin 0.3 working propperly (on Win XP,
with
rails 0.14.3) . Without validation and form redisplay, everythings seems to
work fine, by when I do a form redisplay, then the file-column field is nil
after saving the record, however i have in the hidden formfield the key of
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
end
# Controller
#
........
def create_ebook
return unless request.post?
uploaded_file = params[:book][:file]
@book = Book.new(:file => uploaded_file,
:size => uploaded_file.size,
:title => params[:book][:title],
:amount => params[:book][:amount],
:created_at => Time.now)
current_user.books << @book
if current_user.save
if @ebook.file.nil?
@book.destroy
flash[:notice] = "#{@book[''file'']} upload failed"
else
flash[:notice] = "#{@book[''file'']} uploaded
successfully"
end
redirect_to :action => ''list''
else
@user = current_user
end
end
...................
# 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
--
Roberto Saccon - http://rsaccon.com
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails