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
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) %>
Form title
<%= text_field 'insurance_form', 'form_title' %>
Description
<%= text_area 'insurance_form', 'description' %>
Form document
<%= file_column_field 'insurance_form', 'form_document' %>
<%= 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
Just wanted to say thanks for the info. Even though this was posted
awhile ago, it helped me get my uploading to work!!!