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.
Dave S. (Guest)
on 2009-01-07 16: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!
MaD (Guest)
on 2009-01-07 16:28
(Received via mailing list)
Flower B. (Guest)
on 2009-01-07 16:45
(Received via mailing list)
* MaD <removed_email_address@domain.invalid> [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
MaD (Guest)
on 2009-01-07 16: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.
Dave S. (Guest)
on 2009-01-07 17: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?
Peter De Berdt (Guest)
on 2009-01-07 17:52
(Received via mailing list)
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
Dave S. (Guest)
on 2009-01-07 18: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 %>
Dave S. (Guest)
on 2009-01-07 18: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
Dave S. (Guest)
on 2009-01-08 16: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
Peter De Berdt (Guest)
on 2009-01-08 17:02
(Received via mailing list)
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
Dave S. (Guest)
on 2009-01-08 17:11
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?
Peter De Berdt (Guest)
on 2009-01-08 17:24
(Received via mailing list)
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
Peter De Berdt (Guest)
on 2009-01-08 17:24
(Received via mailing list)
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
Fernando P. (Guest)
on 2009-01-08 17:32
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
Peter De Berdt (Guest)
on 2009-01-08 17:33
(Received via mailing list)
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
Dave S. (Guest)
on 2009-01-08 19: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 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
Peter De Berdt (Guest)
on 2009-01-09 11:21
(Received via mailing list)
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
Sazima (Guest)
on 2009-01-09 16: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 S. <removed_email_address@domain.invalid>
Dave S. (Guest)
on 2009-01-09 16: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 S. <removed_email_address@domain.invalid>

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
Phlip (Guest)
on 2009-01-10 21: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.