Anyone Recommend a File Uploader

Can anyone recommend a good file upload plugin for uploading standard
files (more than one file per article / project), but I am not
interested in images or image processing, just a standard uploader for
files!

attachment_fu is nice.
http://svn.techno-weenie.net/projects/plugins/attachment_fu/README

attachment_fu is nice.
http://svn.techno-weenie.net/projects/plugins/attachment_fu/README

I guess here’s the latest version:

MaD wrote:

I guess here’s the latest version:GitHub - technoweenie/attachment_fu: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.

oh, i’m sorry. i still got some old bookmarks on svn instead of github.

perfect, got it installed and trying to figure out how to get it
working…

project controller in create,

@project_file = Project_File.new(params[:uploaded_data])

in project view,

  <%= f.file_field :uploaded_data %>

the page loads and i can select a file but when i go to save im getting
the error,

ActiveRecord::UnknownAttributeError in ProjectsController#create
unknown attribute: uploaded_data

project has_many :project_files
project_file belongs_to :project

any ideas?

I guess here’s the latest version:GitHub - technoweenie/attachment_fu: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.

oh, i’m sorry. i still got some old bookmarks on svn instead of github.

 Example:
   <% form_for(:attachment_metadata, :url => { :action =>

“create” }, :html => { :multipart => true }) do |form| %>

  1. Use the file_field helper with :uploaded_data as the field name.
    Example:
    <%= form.file_field :uploaded_data %>

I suspect you didn’t include the multipart option.

Best regards

Peter De Berdt

Hi Peter,

Many thanks for your answer, I have included this in my code. This is my
entire new.html.erb file.

<% form_for(@project, :html => {:multipart => true}) do |f| %>
<%= f.error_messages %>

<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :description %>
<%= f.text_field :description %>

<%= f.label :date_due %>
<%= f.calendar_date_select :date_due %>

<%= f.file_field :uploaded_data %>

<%= f.submit "Create" %>

<% end %>

On 07 Jan 2009, at 16:39, Dave S. wrote:

the page loads and i can select a file but when i go to save im
getting
the error,

ActiveRecord::UnknownAttributeError in ProjectsController#create
unknown attribute: uploaded_data

There are two parts of the upload form that differ from typical usage.

  1. Include ‘:multipart => true’ in the html options of the form_for
    tag.
    Example:
    <% form_for(:attachment_metadata, :url => { :action =>
    “create” }, :html => { :multipart => true }) do |form| %>

  2. Use the file_field helper with :uploaded_data as the field name.
    Example:
    <%= form.file_field :uploaded_data %>

I suspect you didn’t include the multipart option.

Best regards

Peter De Berdt

<%= f.label :description %>
<%= f.text_field :description %>

<%= f.label :date_due %>
<%= f.calendar_date_select :date_due %>

<%= f.file_field :uploaded_data %>

<%= f.submit "Create" %>

<% end %>

i forgot to state, that i already had the multipart code in there. so i
dont thin the problem is that

does anyone have any ideas?

projects controller

def create
@project = Project.new(params[:project])
@project.company_id = get_user.company.id
@project.status_id = 2
@project_file = Project_File.new(params[:uploaded_data])

respond_to do |format|
  if @project.save
    flash[:notice] = 'Project was successfully created.'
    format.html { redirect_to(@project) }
    format.xml  { render :xml => @project, :status => :created, 

:location => @project }
else
format.html { render :action => “new” }
format.xml { render :xml => @project.errors, :status =>
:unprocessable_entity }
end
end
end

new project view
<% form_for(@project, :html => {:multipart => true}) do |f| %>
<%= f.error_messages %>

<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :description %>
<%= f.text_field :description %>

<%= f.label :date_due %>
<%= f.calendar_date_select :date_due %>

<%= f.file_field :uploaded_data %>

<%= f.submit "Create" %>

<% end %>

<%= link_to ‘Back’, projects_path %>

project_file model

belongs_to :project
has_attachment :storage => :file_system, :path_prefix =>
‘public/files’, :partition => false
validates_as_attachment

error message

ActiveRecord::UnknownAttributeError in ProjectsController#create

unknown attribute: uploaded_data

RAILS_ROOT: /Users/louisbacon/Sites/codepress
Application Trace | Framework Trace | Full Trace

/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2587:in
attributes=' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2583:ineach’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2583:in
attributes=' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2283:ininitialize’
app/controllers/projects_controller.rb:61:in new' app/controllers/projects_controller.rb:61:increate’

thanks a bunch

On 08 Jan 2009, at 15:33, Dave S. wrote:

@project_file = Project_File.new(params[:uploaded_data])

ProjectFile seems more like an ActiveRecord class name.

Best regards

Peter De Berdt

Peter De Berdt wrote:

On 08 Jan 2009, at 15:33, Dave S. wrote:

@project_file = Project_File.new(params[:uploaded_data])

ProjectFile seems more like an ActiveRecord class name.

Best regards

Peter De Berdt

You’ll have to excuse me for my lack of knowledge here but I dont
understand?

On 08 Jan 2009, at 16:11, Dave S. wrote:

Peter De Berdt

You’ll have to excuse me for my lack of knowledge here but I dont
understand?

script/generate model ProjectFile

class ProjectFile < ActiveRecord::Base

No underscores in model names, that’s not the convention.

Best regards

Peter De Berdt

On 08 Jan 2009, at 16:11, Dave S. wrote:

You’ll have to excuse me for my lack of knowledge here but I dont
understand?

Also, I do hope you have a has_attachment statement in your
ProjectFile model?

Best regards

Peter De Berdt

Dave S. wrote:

Can anyone recommend a good file upload plugin for uploading standard
files (more than one file per article / project), but I am not
interested in images or image processing, just a standard uploader for
files!

Look for paperclip at thoughbot or github. It works perfectly well, and
can handle any type of files.


Video training with screencasts at http://www.digiprof.fr

On 08 Jan 2009, at 15:33, Dave S. wrote:

@project_file = Project_File.new(params[:uploaded_data])

The solution is even more obvious:

ProjectFile.new(params[:project][:uploaded_data]

new project view
<% form_for(@project, :html => {:multipart => true}) do |f| %>
<%= f.file_field :uploaded_data %>
<% end %>

And to be honest, this is not really good code either.

You are manually assigning related record ids instead of relying on
Rails’ built-in safeguards.

I’d advise u to start looking at railscasts.com, starting for very
early ones (complex forms might be a good one for you), getting a
Rails book (The Rails Way, Agile Web D. with Rails) and
getting to know the framework better.

Best regards

Peter De Berdt

And to be honest, this is not really good code either.

You are manually assigning related record ids instead of relying on
Rails’ built-in safeguards.

I’d advise u to start looking at railscasts.com, starting for very
early ones (complex forms might be a good one for you), getting a
Rails book (The Rails Way, Agile Web D. with Rails) and
getting to know the framework better.

Best regards

Peter De Berdt

Hi Peter,

Many thanks for your extensive help on this one. I now have

@project_file = ProjectFile.new(params[:project][:uploaded_data])

in my projects controller.

  <%= f.file_field :uploaded_data %>

but it still says

ActiveRecord::UnknownAttributeError in ProjectsController#create

unknown attribute: uploaded_data

On 08 Jan 2009, at 18:35, Dave S. wrote:

@project_file = ProjectFile.new(params[:project][:uploaded_data])
unknown attribute: uploaded_data
Yes it will. The problem is this: your new project file object expects
the attribute :uploaded_data to be present in the hash you are passing
it.

@project_file = ProjectFile.new(params[:project])

This will pass in a hash that’s too large (since it also holds your
project related attributes, but it will probably save the object for
you. That’s the reason you need to get familiar with fat models,
skinny controllers. It will make mass assignments and related object
creation so much easier.

The only code that should be in your controller is that to assign the
instance variable with a newly created object. I would then let my
model handle the object creation, including the related record. In
fact, that is the exact thing the model is there for.

def create
@project = Project.create(params[:project])
end

Best regards

Peter De Berdt

attachment_fu, file_column, paperclip (nice railscast)

Ifo you need multiple concurrent uploads, go for something in flash…

Cheers, Sazima

On Jan 7, 12:13 pm, Dave S. [email protected]

Sazima wrote:

attachment_fu, file_column, paperclip (nice railscast)

Ifo you need multiple concurrent uploads, go for something in flash…

Cheers, Sazima

On Jan 7, 12:13�pm, Dave S. [email protected]

thank you all for your help! its greatly appreciated! ive gone with
another method of multiple attachments using attachment fu, and am
learning fat models and skinny controllers to help in general.

cheers folks

dave

Responding to the subject line: Please register another vote for
Paperclip; it
rules!