Forum: Ruby on Rails Anyone Recommend a File Uploader

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.
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-07 15:13
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!
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-01-07 15:28
(Received via mailing list)
8853f712852b03ba6646b59b1723f44d?d=identicon&s=25 Flower Born (flowerborn)
on 2009-01-07 15:45
(Received via mailing list)
* MaD <mayer.dominik@gmail.com> [2009-01-07 06:17:27 -0800]:

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

I guess here's the latest version:
http://github.com/technoweenie/attachment_fu/tree/master
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-01-07 15:55
(Received via mailing list)
> I guess here's the latest 
version:http://github.com/technoweenie/attachment_fu/tree/master

oh, i'm sorry. i still got some old bookmarks on svn instead of github.
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-07 16:39
MaD wrote:
>> I guess here's the latest 
version:http://github.com/technoweenie/attachment_fu/tree/master
>
> 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?
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2009-01-07 16:52
(Received via mailing list)
On 07 Jan 2009, at 16:39, Dave Smith 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
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-07 17:05
>      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

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 %>
   <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :description %><br />
    <%= f.text_field :description %>
  </p>
  <p>
    <%= f.label :date_due %><br />
    <%= f.calendar_date_select :date_due %>
  </p>
    <p>
      <%= f.file_field :uploaded_data %>
    </p>
  <p>
    <%= f.submit "Create" %>
  </p>
<% end %>
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-07 17:06
>   <p>
>     <%= f.label :description %><br />
>     <%= f.text_field :description %>
>   </p>
>   <p>
>     <%= f.label :date_due %><br />
>     <%= f.calendar_date_select :date_due %>
>   </p>
>     <p>
>       <%= f.file_field :uploaded_data %>
>     </p>
>   <p>
>     <%= f.submit "Create" %>
>   </p>
> <% end %>

i forgot to state, that i already had the multipart code in there. so i
dont thin the problem is that
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-08 15:33
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 %>
   <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :description %><br />
    <%= f.text_field :description %>
  </p>
  <p>
    <%= f.label :date_due %><br />
    <%= f.calendar_date_select :date_due %>
  </p>
    <p>
      <%= f.file_field :uploaded_data %>
    </p>
  <p>
    <%= f.submit "Create" %>
  </p>
<% 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:in
`each'
/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:in
`initialize'
app/controllers/projects_controller.rb:61:in `new'
app/controllers/projects_controller.rb:61:in `create'

thanks a bunch
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2009-01-08 16:02
(Received via mailing list)
On 08 Jan 2009, at 15:33, Dave Smith wrote:

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

ProjectFile seems more like an ActiveRecord class name.


Best regards

Peter De Berdt
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-08 16:11
Peter De Berdt wrote:
> On 08 Jan 2009, at 15:33, Dave Smith 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?
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2009-01-08 16:24
(Received via mailing list)
On 08 Jan 2009, at 16:11, Dave Smith 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
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2009-01-08 16:24
(Received via mailing list)
On 08 Jan 2009, at 16:11, Dave Smith 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
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-01-08 16:32
Dave Smith 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
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2009-01-08 16:33
(Received via mailing list)
On 08 Jan 2009, at 15:33, Dave Smith 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 Development with Rails) and
getting to know the framework better.


Best regards

Peter De Berdt
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-08 18:35
>
> 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 Development 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
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2009-01-09 10:21
(Received via mailing list)
On 08 Jan 2009, at 18:35, Dave Smith 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
Fac81a9d95c81d817a2debb6f717f3ac?d=identicon&s=25 Sazima (Guest)
on 2009-01-09 15:03
(Received via mailing list)
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 Smith <rails-mailing-l...@andreas-s.net>
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-09 15:07
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 Smith <rails-mailing-l...@andreas-s.net>

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.

http://www.practicalecommerce.com/blogs/post/432-M...

cheers folks

dave
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-10 20:41
(Received via mailing list)
Responding to the subject line: Please register another vote for
Paperclip; it
rules!
This topic is locked and can not be replied to.