Adding upload_column to a form

3 views
Skip to first unread message

EMS

unread,
Dec 18, 2008, 6:17:32 PM12/18/08
to Streamlined
I have added upload_column into my application so I can do a simple
file upload. Following along with everything I've seen here, in the
upload_column site, and the streamlinedframework docs, I have done the
following:

1) Added my upload column to my model:

upload_column :sFileName,
:root_path => FILE_UPLOAD_CFG[RAILS_ENV][:file_upload_root],
:store_dir => FILE_UPLOAD_CFG[RAILS_ENV][:file_upload_path]

2) Added the magic columns to my migration and migrated the database.

# Table already contains sFileName of type :string
def self.up
add_column :tblMain, :sFileName_mime_type, :string
add_column :tblMain, :sFileName_filesize, :integer
end

3) Altered the _form.rhtml to handle the field

<% model_ui.edit_columns.each do |column| %>
<% if column.name.to_sym == :sFileName %>

<tr id="sl_field_media">
<td class="sl_edit_label"><label for=<%="#{form.object_name}
_sFileName"%>><%= column.human_name %></label></td>
<td class="sl_edit_value"><%= upload_column_field
form.object_name, 'sFileName' %></td>
</tr>

<% elsif column.is_displayable_in_context?(self,
@streamlined_item) %>
<%= column.render_tr_edit(self, @streamlined_item) %>
<% end %>
<% end %>


4) Made my new.rhtml and edit.rhtml use multipart

from new.rhtml
<% options[:html] = {:onsubmit=>'Streamlined.Form.submit(this);
return false;', :multipart => true} %>

from edit.rhtml
<% options[:html] = {:onsubmit=>'Streamlined.Form.submit(this);
return false;', :multipart => true} %>


Now when I run my app, I get the form (and viewing the form source, I
can see that the fields appear to match up against the database, and
that the form is marked for 'multipart/form-data'

But when I click the "Create" button, I receive an Upload Not
Multipart Error from uploaded_file.rb(72)

"Do not know how to handle a string with value 'testfile.csv' that was
uploaded. Check if the form's encoding has been set to 'multipart/form-
data'"


So my questions are:

1) Has anyone successfully integrated a file upload using
upload_column? If so, can you send/post an example for download so I
can see what is missing?

2) Has anyone been successful with another file upload tool
(attachment_fu, paperclip, etc...) and if so, can you post an example
for download so I can see what is missing?

Or, if something prohibits you from posting an example, can you
provide some hints about what steps have been missed?

Sincereley,

EMS

Giovanni Nicolazzo

unread,
Dec 19, 2008, 4:00:51 AM12/19/08
to strea...@googlegroups.com

hi,
due javascript limitation upload doesn't working with ajax.
Try this:

Streamlined.ui_for(YOUR_Attachment_MODEL) do
new_submit_button :ajax => false
edit_submit_button :ajax => false
end

in the views

<!-- never enter here-->
<% if model_ui.new_submit_button[:ajax] %>

<% options[:html] = {:onsubmit=>'Streamlined.Form.submit(this); return

false;'} %>
<% else %>
<!-- multipart option-->
<% options[:html] = {:multipart=>true} %>

> 2) Has anyone been successful with another file upload tool
> (attachment_fu, paperclip, etc...) and if so, can you post an example
> for download so I can see what is missing?

sorry, i have made a step-by-step tutorial for file column and attachment_fu
but in italian language ;)
bye
--
Giovanni Marco Nicolazzo
www.railshosting.it

sergio_101

unread,
Jan 8, 2009, 1:11:25 AM1/8/09
to Streamlined

hey, guys.. i spent some time unraveling this during the week.. i got
it to work.. for more information, check here:

http://www.village-buzz.com/2009/01/07/using-upload_column-with-streamlined/
Reply all
Reply to author
Forward
0 new messages