Forum: Ruby on Rails FileColumn help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alex Castro (Guest)
on 2006-01-15 06:01
(Received via mailing list)
I'm trying to upload an image that will be displayed alongside a user
profile.
I've been trying to use FileColumn but haven't had any luck. I don't
receive any
errors, I just don't get the file on the server.

Does anyone have any sample code they could share that demonstrates how
I should
use FileColumn?

Thx
Alex
sross (Guest)
on 2006-01-15 06:12
Be certain your upload forms are multipart. Here is some working code.

in the model
----------

class InsuranceForm < ActiveRecord::Base
  file_column :form_document
  validates_presence_of :form_title
  validates_presence_of :description
  validates_presence_of :form_document
end

in the view
---------

<%= error_messages_for 'insurance_form' %>

<%= start_form_tag({:action => 'create'}, :multipart => true) %>
<p><label for="insurance_form_form_title">Form title</label><br/>
<%= text_field 'insurance_form', 'form_title'  %></p>

<p><label for="insurance_form_description">Description</label><br/>
<%= text_area 'insurance_form', 'description'  %></p>

<p><label for="insurance_form_form_document">Form document</label><br/>
<%= file_column_field 'insurance_form', 'form_document'  %></p>
<%= end_form_tag %>

<%= link_to 'Back', :action => 'list' %>

in the controller
--------------

def new
    @insurance_form = InsuranceForm.new
  end

  def create
    @insurance_form = InsuranceForm.new(params[:insurance_form])
    if @insurance_form.save
      flash[:notice] = 'InsuranceForm was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end
mike (Guest)
on 2007-03-15 23:29
Just wanted to say thanks for the info.  Even though this was posted
awhile ago, it helped me get my uploading to work!!!
This topic is locked and can not be replied to.