AJAX file uploads in Rails using attachment_fu and responds_to_parent

written by kam on May 1st, 2007 @ 11:27 PM

In this walkthrough, I go through the available options and an example using attachment_fu to handle file uploads and image thumbnailing, and responds_to_parent to implement the iframe remoting pattern to work around javascript’s security restrictions on file system access.

You can also download the complete example.

Step 1. Choose a file upload plugin

Sure, you can write one yourself (or bake the code directly into your app), but unless you have specific requirements you should take a look at what’s already there. Even if you do have a good excuse, you can learn from the existing plugins or extend them. The three that I’ve used over the past two years are:

  1. file_column – the first file upload plugin available for Rails that I know of, it handles saving files to the filesystem, resizing of images, creation of thumbnails, and integration with rmagick; however it doesn’t seem to be in active development.
  2. acts_as_attachment – written by Rick Olson, it does everything that file_column can, but with a cleaner and extensible code base.
  3. attachment_fu – is a rewrite of acts_as_attachment adding a plugin architecture to extend it to add different image processors (image_science, mini_magick and rmagick are provided) and storage backends (database, file system, and Amazon S3). The only problem is you need Rails 1.2+

Recommendation: attachment_fu if you are using Rails 1.2+, otherwise acts_as_attachment.

Step 2. Determine which Image Processor you want to use.

attachment_fu supports three processors out of the box:
  1. image_science – a light ruby wrapper around the FreeImage library, it can only be used to resize images. It used to have problems with image quality of thumbnails and PNG color profiles but these have recently been fixed.
  2. RMagick – a ruby wrapper around the ImageMagick/GraphicsMagick libraries, it provides a lot of advanced image processing features. It’s memory hungry though, and can max resource limits on some shared hosts causing your app to fail; it’s happened to me a few times on large images.
  3. minimagick – another wrapper around ImageMagick, however it resizes images using imagemagick’s mogrify command. If you are hitting resource limits on your host, minimagick is preferred over rmagick.

Recommendation: image_science if you only need image resizing and can handle the slightly inferior thumbnail quality, minimagick otherwise.

Step 3. Install image processors and attachment_fu

The installation process is quite long for the image processors, so I’ve just linked to them here:

  • RMagick/ImageMagick: Mac OS X, Linux, and Windows
  • FreeImage/image_science: Mac OS X, Linux
  • To install minimagick:
    sudo gem install mini_magick
  • To install attachment_fu:
    script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/

Step 4. Add uploading to your code

I’ll use a restful model for our file uploads since it’s all the rage (here’s a good introduction). You can create a restful scaffold using the following command:
ruby script/generate scaffold_resource asset filename:string content_type:string size:integer width:integer height:integer parent_id:integer thumbnail:string created_at:datetime

This will create the controllers, models, views and a migration. I’ve included support for saving image properties (width and height attributes) and thumbnailing (parent_id and thumbnail attributes).

Here is the resulting migration if you want to do it manually:
class CreateAssets < ActiveRecord::Migration
  def self.up
    create_table :assets do |t|
      t.column :filename,     :string
      t.column :content_type, :string
      t.column :size,         :integer
      t.column :width,        :integer
      t.column :height,       :integer
      t.column :parent_id,    :integer
      t.column :thumbnail,    :string
      t.column :created_at,   :datetime
    end    
  end

  def self.down
    drop_table :assets
  end
end

In the model, it’s really a one liner to add file upload features.

class Asset < ActiveRecord::Base

  has_attachment  :storage => :file_system, 
                  :max_size => 1.megabytes,
                  :thumbnails => { :thumb => '80x80>', :tiny => '40x40>' },
                                    :processor => :MiniMagick # attachment_fu looks in this order: ImageScience, Rmagick, MiniMagick

  validates_as_attachment # ok two lines if you want to do validation, and why wouldn't you?
end

The has_attachment (or acts_as_attachment method for those not using attachment_fu) adds a lot of useful methods such as image? to determine if the file is an image, and public_filename(thumbnail=nil) to retrieve the filename for the original or thumbnail. I usually add methods to determine other file types such as movies, music, and documents.

The options available are:

  • content_type – Allowed content types. Allows all by default. Use :image to allow all standard image types.
  • min_size – Minimum size allowed. 1 byte is the default.
  • max_size – Maximum size allowed. 1.megabyte is the default.
  • size – Range of sizes allowed. (1..1.megabyte) is the default. This overrides the :min_size and :max_size options.
  • resize_to – Used by RMagick to resize images. Pass either an array of width/height, or a geometry string.
  • thumbnails – Specifies a set of thumbnails to generate. This accepts a hash of filename suffixes and RMagick resizing options.
  • thumbnail_class – Set what class to use for thumbnails. This attachment class is used by default.
  • path_prefix – path to store the uploaded files. Uses public/#{table_name} by default for the filesystem, and just #{table_name} for the S3 backend. Setting this sets the :storage to :file_system.
  • storage – Use :file_system to specify the attachment data is stored with the file system. Defaults to :db_system.

In the above we’re storing the files in the file system and are adding two thumbnails if it’s an image: one called ‘thumb’ no bigger than 80×80 pixels, and the other called ‘tiny’. By default, these will be stored in the same directory as the original: /public/assets/nnnn/mmmm/ with their thumbnail name as a suffix. To show them in the view, we just do the following: <%= image_tag(image.public_filename(:thumb)) %>

validates_as_attachment ensures that size, content_type and filename are present and checks against the options given to has_attachment; in our case the original should be no larger than 1 megabyte.

Next, we’ll work on the view code. To enable multipart file uploads, we need to set multipart => true as a form option in new.rhtml. The uploaded_data file input field is used by attachment_fu to store the file contents in an attribute so that attachment_fu can do its magic when the uploaded_data= method is called.

<%= error_messages_for :asset %>
<% form_for(:asset, :url => assets_path, :html => { :multipart => true }) do |form| %>
  <p>
    <label for="uploaded_data">Upload a file:</label>
    <%= form.file_field :uploaded_data %>
  </p>
  <p>
    <%= submit_tag "Create" %>
  </p>
<% end %>

We’ll also pretty up the index code. We want to show a thumbnail if the file is an image, otherwise just the name:

<h1>Listing assets</h1>

<ul id="assets">
<% @assets.each do |asset| %>
<li id="asset_<%= asset.id %>">
<% if asset.image? %>
<%= link_to(image_tag(asset.public_filename(:thumb))) %><br />
<% end %>
<%= link_to(asset.filename, asset_path(asset)) %> (<%= link_to "Delete", asset_path(asset), :method => :delete, :confirm => "are you sure?"%>)
</li>
<% end %>
</ul>

<br />

<%= link_to 'New asset', new_asset_path %>

Don’t forget to do a rake db:migrate to add the assets table. At this stage you can start your server and go to http://localhost:3000/assets/new to add a new file. After being redirected back to the index page you’ll notice that thumbnails are showing in our index with the originals. To get rid of this, we can modify assets_controller to only display originals by checking if the parent_id attribute is nil. attachment_fu also allows you to store thumbnails into a different model, which would make this step unnecessary.

  def index
    @assets = Asset.find(:all, :conditions => {:parent_id => nil}, :order => 'created_at DESC')
    respond_to do |format|
      format.html # index.rhtml
      format.xml  { render :xml => @assets.to_xml }
    end
  end

Step 5. AJAX it

Let’s try and AJAX our file uploads. The current user flow is:

  • go to index page
  • click on “new file” link
  • choose a file and submit the form
  • get redirected to index.

What we want to happen is to have all that occur on the index page, with no page refreshes. Normally you would do the following:

Add the Javascript prototype/scriptaculous libraries into your layout.

<%= javascript_include_tag :defaults %>

Change the form_for tag to a remote_form_for

<% remote_form_for(:asset, :url => assets_path, :html => { :multipart => true }) do |f| %>

Add format.js to the create action in the controller to handle AJAX requests:

  def create
    @asset = Asset.new(params[:asset])
    respond_to do |format|
      if @asset.save
        flash[:notice] = 'Asset was successfully created.'
        format.html { redirect_to asset_url(@asset) }
        format.xml  { head :created, :location => asset_url(@asset) }
        format.js
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @asset.errors.to_xml }
        format.js
      end
    end
  end

Make a create.rjs file to insert the asset at the bottom of your list:

page.insert_html :bottom, "assets", :partial => 'assets/list_item', :object => @asset
page.visual_effect :highlight, "asset_#{@asset.id}" 

Create a partial to show the image in the list

<li id="asset_<%= list_item.id %>">
<% if list_item.image? %>
<%= link_to(image_tag(list_item.public_filename(:thumb))) %><br />
<% end %>
<%= link_to(list_item.filename, asset_path(list_item))%> (<%= link_to_remote("Delete", {:url => asset_path(list_item), :method => :delete, :confirm => "are you sure?"}) %>)
</li>

Add AJAX deletion (optional)

If you’ve noticed the changes in the previous code, I’ve added AJAX deletion of files as well. To enable this on the server we add a destroy.rjs file to remove the deleted file form the list.

page.remove "asset_#{@asset.id}" 

In the controller you also need to add format.js to the delete action.

Keep our form views DRY (optional)

We should also make the file upload form contents into a partial and use it in new.rhtml as well as index.rhtml.

_form.rhtml
  <p>
    <label for="uploaded_data">Upload a file:</label>
    <%= form.file_field :uploaded_data %>
  </p>
  <p>
    <%= submit_tag "Create" %>
  </p>
new.rhtml
<% form_for(:asset, :url => assets_path, :html => { :multipart => true }) do |form| %>
<%= render(:partial => '/assets/form', :object => form)%>
<% end %>

Add the form to index.rhtml

<% remote_form_for(:asset, :url => assets_path, :html => { :multipart => true }) do |form| %>
<%= render(:partial => '/assets/form', :object => form) %>
<% end %>

Now that we have all our code in place, go back to the index page where you should be able to upload a new file using AJAX. The new file should appear at the bottom of our list of files with a visual highlight!

Unfortunately there is only one problem. There is a security restriction with javascript to prevent access to the filesystem. If you used validations for your asset model you would have gotten an error complaining about missing attributes. This is because only the filename is sent to the server, not the file itself. How can we solve this issue?

Step 6. Using iframes and responds_to_parent

To get around the AJAX/file upload problem we make use of the iframe remoting pattern. To do this we need a hidden iframe and target our form’s action to that iframe. First, we change the index.rhtml to go back to using a form_for tag. But how will we get rails to process our action like an AJAX request you ask? We simply add a ”.js” extension to the form’s action! We then set the iframe to a 1×1 sized pixel so it doesn’t get shown. Don’t use display:none otherwise your iframe will be hidden from your form depending on your browser you will end up opening a new window, loading the server response in the main window, or downloading the server response as a file.

<% form_for(:asset, :url =>formatted_assets_path(:format => 'js'), :html => { :multipart => true, :target => 'upload_frame'}) do |form| %>
<%= render(:partial => '/assets/form', :object => form) %>
<% end %>
<iframe id='upload_frame' name="upload_frame" style="width:1px;height:1px;border:0px" src="about:blank"></iframe>
To handle the form on the server, we can use Sean Treadway’s responds_to_parent plugin.
script/plugin install http://responds-to-parent.googlecode.com/svn/trunk/

This plugin makes it dead simple to send javascript back to the parent window, not the iframe itself. You need to restart your server to load the plugin.

Just add the following to your create action in the controller:

def create
  @asset = Asset.new(params[:asset])
  respond_to do |format|
    if @asset.save
      flash[:notice] = 'Asset was successfully created.'
      format.html { redirect_to asset_url(@asset) }
      format.xml  { head :created, :location => asset_url(@asset) }
      format.js do
        responds_to_parent do
          render :update do |page|
            page.insert_html :bottom, "assets", :partial => 'assets/list_item', :object => @asset
            page.visual_effect :highlight, "asset_#{@asset.id}" 
          end
        end          
      end
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @asset.errors.to_xml }
      format.js do
        responds_to_parent do
          render :update do |page|
              # update the page with an error message
          end
        end          
      end
    end
  end
end

At this point you no longer need the create.rjs file.

NOW you should be able to get your index page and upload a file the AJAX way!

Step 7. Make it production ready

There are some more changes you need to make it production ready:

  • handling errors,
  • displaying error messages when uploading fails,
  • showing some feedback to the user – such as a spinner – while the file is uploading or being deleted

But most of the head scratching work is done. Hope that helps.

Step 8. Bonus: making a file download by clicking on a link

Just add the following action to your assets controller; don’t forget to add the route to your routes.rb file.
  def download
    @asset = Asset.find(params[:id])
    send_file("#{RAILS_ROOT}/public"+@asset.public_filename, 
      :disposition => 'attachment',
      :encoding => 'utf8', 
      :type => @asset.content_type,
      :filename => URI.encode(@asset.filename)) 
  end

Update: 2007/05/23 Thanks to Geoff Buesing for pointing out that we can use formatted_routes.

Update: 2007/05/26 Updated a bug in the initial index.html example (thanks Benedikt!) and added a download link to the final example (see the first paragraph).

Comments

  • dazza on 19 May 17:17

    this is a great tutorial…

    the only part of this or any a_fu tut I don’t get is the named route e.g. :url => assets_path when you post the new image…

    how does this work do you create a map in routes.rb to assets_path ???

    cheers

  • Khamsouk Souvanlasy on 20 May 01:34

    dazza, you need to add the following line in routes.rb:

    map.resources :assets

    This should already have been added to routes.rb with the command:

    ruby script/generate scaffold_resource ...

    in step 4.

  • Khamsouk Souvanlasy on 20 May 01:53

    Sorry dazza, I don’t think I really answered your question. With restful controllers in rails, if you do add the routes.rb bit above, it makes available these methods to your controllers and views:

    • assets_path (GET => index action, POST => create action)
    • asset_path(id) (GET => show action, PUT => update action, DELETE => destroy action)
    • new_asset_path (GET => new action)
    • edit_asset_path(id) (edit action)
  • since1968 on 22 May 02:38

    Thanks for this tut. Will it work with lighttpd?

  • Geoff Buesing on 22 May 04:21

    Helpful stuff, thanks!

    Fyi, with map.resources you get also formatted_ routes, so instead of:

    assets_path + ”.js”

    you can do:

    formatted_assets_path(:js)

  • James Roth on 22 May 14:20

    I want to use attachment_fu, as it is the most up-to-date attachment plugin, but it still doesn’t handle cropping or on-the-fly resizing of images. File_column can do both.

  • Hal Robertson on 22 May 14:48

    Any chance you could post a link to a live app so we can see what the end-result should look like?

  • Khamsouk Souvanlasy on 24 May 00:18

    James, you might want to checkout Jon Dahl’s blog for information about cropping with attachment_fu. In terms of doing on the fly image resizing, just delve into the attachment_fu resizing code. Actually, I have to do that for a project I’m on right now, so I’ll post it on this blog with a part two to this article about handling polymorphic attachments that I’m working on at the moment.

    Geoff, I’ve changed the article to use formatted_routes, thanks for the tip!

    Hal, I can certainly put one up, or maybe even let you guys download some sample code?

  • Hal Robertson on 25 May 08:43

    That would be stellar!

  • Benedikt on 26 May 13:36

    Hallo!

    Along with [write-up] “After being redirected back to the index page you’ll notice [...]” I receive the following errot message:

    SyntaxError in Assets#index
    
    Showing app/views/assets/index.rhtml where line #9 raised:
    
    compile error
    script/../config/../app/views/assets/index.rhtml:9: syntax error, unexpected '(', expecting ')'
    _erbout.concat(( link_to(asset.filename, asset_path(asset) (<%= link_to "Delete", asset_path(asset), :method => :delete, :confirm => "are you sure?").to_s); _erbout.concat ")) %>\n"
                                                                ^
    script/../config/../app/views/assets/index.rhtml:
    9: syntax error, unexpected ',', expecting ')'
    _erbout.concat(( link_to(asset.filename, asset_path(asset) (<%= link_to "Delete", asset_path(asset), :method => :delete, :confirm => "are you sure?").to_s); _erbout.concat ")) %>\n"
                                                                                                                            ^
    
    Extracted source (around line #9):
    
    6: <% if asset.image? %>
    7: <%= link_to(image_tag(asset.public_filename(:thumb))) %>
    8: <% end %> 9: <%= link_to(asset.filename, asset_path(asset) (<%= link_to "Delete", asset_path(asset), :method => :delete, :confirm => "are you sure?"%>)) %> 10: </li> 11: <% end %> 12: </ul>

    Any help?

    Thank you so much!

    B.

  • Khamsouk Souvanlasy on 26 May 22:44

    Benedikt, Looks like a bad cut and paste job by me!

    The link to should read:
    <%= link_to(asset.filename, asset_path(asset)) %> (<%= link_to "Delete", asset_path(asset), :method => :delete, :confirm => "are you sure?"%>)
    
  • Khamsouk Souvanlasy on 26 May 23:31

    A download of the example code can be found here

  • Nola on 29 May 22:24

    Hey, I am trying attachment_fu and it doesn’t look like it moves the image? I am using windows (for development) and I don’t need to resize anything or have thumbnails, so I’m not using any image processor. Can’t find any other docs on attachment_fu. :(

  • Khamsouk Souvanlasy on 30 May 09:08

    Nola, I’m not sure what you mean by it doesn’t move the image? Do you mean between your development machine and another server? Or are you talking about manipulation of the actual image on an upload.

  • Benedikt on 31 May 13:39

    Hallo Khamsouk!

    In your downloadables the ‘plugins’ – directory is nested in inself – I don’t know if that’s supposed to work … you may have a look in case …

    thanx!

    B.

  • Benedikt on 31 May 13:51

    obsolete, sorry, this was bad use of winscp…

    by the way: did you ever consider using svn to provide your sample downloadeables?

    Thanx again.

    B.

  • Benedikt on 31 May 13:54

    obsolete, sorry, this was bad use of winscp…

    by the way: did you ever consider using svn to provide your sample downloadeables?

    Thanx again.

    B.

  • Benedikt on 31 May 13:59

    (the Mephisto -comment form produces strange error messages; something like ‘rails app failed to …properly ’ ... )

    ever considered using the radiant cms?

    http://radiantcms.org

    That’s what I’m trying to do – and it would be great to have your ‘uploadr’ running within as a so called extension!

    Any ideas?

    B.

  • khamsouk Souvanlasy on 31 May 15:41

    I have noticed that problem with my blog. I am using dreamhost and sometimes I get those errors. I might be switching to another host since I am getting more traffic than dreamhost seems to be able to handle.

    Radiant CMS is nice, but I felt the tree structure was not very intuitive for a blog.

  • Gunner Bob II on 09 Jun 18:20

    I found another link that goes well this this tutorial, it describes how to override methods in the plugin to modify the standard functionality. They used the example of changing the way that the pictures are stored in the filesystem, but it makes a really good read.

    http://www.dotrb.com/2007/6/9/attachment_fu-and-restful_authentication

  • Sree on 09 Jun 20:48

    A great tutorial. Thanks. I tried out with a simple text file and it worked. But looks like the file gets stored in the public directory and by giving the exact url the document gets displayed. Can be kind of a security concern. Looks like attachment_fu does not have an alternate option. Any suggestions for overcoming this?

    Sree

    ps: Iam a rails newbie

  • Sree on 09 Jun 20:54

    Hi Bob,

    Looks like our posts crossed the wire. Your comment seems to be an answer to my post. I will look at the dotrb url.

    Thanks

    Sree

  • Tony on 14 Jun 07:48

    I have tried this and it all works very, very well. However, I cannot seem to get the images to resize, do thumbnails and such. I also can’t seem to be able to simply destroy the asset.

    I have mini_magick gem installed.

    Any other suggestions?

  • Tirta on 15 Jun 02:18

    This works very well. However, I need to store those uploaded images in the database. How can I modify codes from this tutorial to do so? I tried several times to modify the code with no success. Thanks for you time.

  • brendan on 22 Jun 12:39

    This saved me from tearing out much hair, Thanks! I did have one issue while re-arranging the list, the syntax :

    <% if asset.image? %>

    was giving me trouble for some reason.

    <% if !asset.parent_id? %>

    got me the desired result for anyone else having trouble. Thanks again!

  • Chirag Patel on 24 Jun 06:10

    What changes would I make in general if I was using it to upload just a plain .txt file.

    1. What parameters would I change and/or add methods to the Asset model (step 4) to do this? Could someone show an example?

    2. I’m using REST from a .NET client to upload the file. How does a REST post for a file work from a non-web client?

    Thanks! Chirag

  • satyanarayana on 27 Jun 23:52

    hi this is very nice tutorial,i have seen.

    can i know where can i find example programs for uploading file,downloading file,staging a file to another location other to server.

  • Matt on 02 Jul 23:37

    Hey there,

    One thing that’s not quite obvious from any documentation I’ve seen, nor from the source code, is: what happens when you decide you need to add another thumbnail size, but you already have a bunch of photos uploaded? Is there an easy way to ensure that the missing thumbnails are generated automatically?

    Thanks, Matt

  • dave on 04 Jul 09:04

    Thanks for the great tutorial! I was able to get this part to work, and was struggling with having a spinner display while a file was uploading. Do you have an example of implementing this last part?

    Thanks!

  • Brad on 13 Jul 23:49

    @Chirag Patel,

    If you look at the Attachment_fu readme it gives the example, “has_attachment :content_type => [‘application/pdf’, ‘application/msword’, ‘text/plain’]”

  • Brad on 13 Jul 23:52

    @Tirta

    In the attachment_fu readme it tells you to create a 2nd table called db_files. This is the default method for storage so you don’t have to change anything.

  • Chirag Patel on 16 Jul 07:58

    I had a lingering problem with using attachment_fu on my hosted ‘production’ server. When I transferred the code from Windows to Textdrive (Solaris), it stopped working. After some debugging and logging, I noticed that the ‘create’ action was not being registered by Rails. The ‘new’ action would jump straight to the ‘index’ action, which is a display list of the uploaded files. Thanks to Steve Eichert‘ June 20, 2007 blog entry, I found a workaround. Add this to the body of the ApplicationController class in application.rb :

    def default_url_options(options)
    { :trailing_slash => true }
    end
  • Emil Kampp on 18 Jul 07:25

    Hi there. I for some reason cant get these line to work properly.

    :resize_to => [“300”, “300”], :thumbnails => { :thumb => [“200”, “200”], :icon => [“100”, “100”], :tiny => [“50”, “50”] }

    This will generete the proper copies, but none of them will be resized. If i use the “100×100>” (or another size) only the original will be saved. But still no resizing. Im using the MiniMagic as the processor.

  • Attila on 28 Jul 04:00

    Hi Folks.

    Got attachment_fu uploading photos this morning but only without validation (i.e. validates_as_attachment commented out). When I enable validation I get an error

    "Validation failed: Size is not included in the list"

    which is strange, since if I disable validations, and look at the populated entries in the associated photo_attachments database table, it seems to have done a fine job, creating an entry for the original photo (resized and all) and a thumbnail … and both entries have their ‘size’ field filled in appropriately.

    Anyone come across this ?. All I can add is that it’s a registration form that ends up posting data for 2 models (place data and photo data). I’m uploading the photo (which will end up in the photo_attachments table) with a place_controller that’s taking the actual ‘place’s detailed information. So, in effect I’m using a form_for for ‘place’ but then adding a ‘file_field’ for ‘photo_attachment’. It works if the attachment_fu validations_as_attachment is not used.

    Oh … and I’m not using RESTful controllers :0(. It just doesn’t seem to fit my application, but what do I know :0).

    What would be good, and I’ve not found it thus far, is an example of using attachment_fu when the form being used is to create data for more than one model. All the examples I’ve seen deal with a single model (therefore table) at a time. Wouldn’t it be more realistic to take say registration details of a user or some such, and allow them to attach a photo .. and the user details goes into a Users table and the photo goes into an Attachments table ?. I’ve not seen examples of that anywhere.

    Finally … RESTful applications are fine, but an example of a REST-less app using attachment_fu (maybe for the above ?) would be good for the ‘rest’ of us (‘scuse the pun) :0)

    Any ideas … thanks in advance, Attila

  • Attila on 28 Jul 04:08

    Hi Folks.

    Got attachment_fu uploading photos this morning but only without validation (i.e. validates_as_attachment commented out). When I enable validation I get an error

    "Validation failed: Size is not included in the list"

    which is strange, since if I disable validations, and look at the populated entries in the associated photo_attachments database table, it seems to have done a fine job, creating an entry for the original photo (resized and all) and a thumbnail … and both entries have their ‘size’ field filled in appropriately.

    Anyone come across this ?. All I can add is that it’s a registration form that ends up posting data for 2 models (place data and photo data). I’m uploading the photo (which will end up in the photo_attachments table) with a place_controller that’s taking the actual ‘place’s detailed information. So, in effect I’m using a form_for for ‘place’ but then adding a ‘file_field’ for ‘photo_attachment’. It works if the attachment_fu validations_as_attachment is not used.

    Oh … and I’m not using RESTful controllers :0(. It just doesn’t seem to fit my application, but what do I know :0).

    What would be good, and I’ve not found it thus far, is an example of using attachment_fu when the form being used is to create data for more than one model. All the examples I’ve seen deal with a single model (therefore table) at a time. Wouldn’t it be more realistic to take say registration details of a user or some such, and allow them to attach a photo .. and the user details goes into a Users table and the photo goes into an Attachments table ?. I’ve not seen examples of that anywhere.

    Finally … RESTful applications are fine, but an example of a REST-less app using attachment_fu (maybe for the above ?) would be good for the ‘rest’ of us (‘scuse the pun) :0)

    Any ideas … thanks in advance, Attila

  • Attila on 28 Jul 21:55

    Hi again,

    Sorry ‘bout the double post earlier (accident). Ran into a second problem now, to do with views. I’ve spent the last day and a half trying to get photos associated with a ‘place’ onto a sidebar list. Some context …

    I have a partial called _item.rhtml being called by find.rjs that contains the line ..

    @search_results.each { |result| page.insert_html :bottom, :sidebar_list, render(:partial => “item”, :layout => false, :object => result) }

    The ‘result’ being passed to the partial is a Place object, but the photo_attachment is in an associated table with associated model PhotoAttachment.

    The partial _item.rhtml contains a link_to_remote, embedded within which I’ve hardcoded a value 16 (which is just a place_id that happens to exist) .. which makes the partial work … well … sorta … if every Place were to have the same photo !.

    <%= link_to_remote “” ,:url => { :action => ‘details’, :place_id => ”#{item.id}”}, :update => ‘details’ %>

    That works. However, if I replace the hardcoded value, with item.id the substitution fails, and I get an exception complaining about a nil object …

    ActionView::TemplateError (You have a nil object when you didn’t expect it! The error occurred while evaluating nil.public_filename) on line #2 of app/views/place/_item.rhtml:

    I’ve tried every variant I can think of to get the image tag working, but the above hardcoded variant is the only one that does. I’ve tried defining a method ‘thumbnail’ in my Place model which does the lookup on PhotoAttachment, I’ve tried using an :include in the original search and referencin through to :photo_attachments, since the Place and PhotoAttachments models have a has_many/belongs_to relationship, and I’ve tried various erb variants within the partial.

    I’m about to give up, and try something else. The problem is that I’m still relatively a rookie re: Ruby and Rails, so it’s not that attachments_fu has a problem, but that I can’t figure out how to use it within a partial .. when the attachment is in a different Model than that given to the partial.

    Any help … GREATLY appreciated ..

    Thanks in Advance, Attila

  • Attila on 28 Jul 22:08

    Sorry … the link_to_remote sample is missing the image tag line in question between the quotes ..

    
    <img src=#{PhotoAttachment.find_by_place_id(16).public_filename(:thumb)}
    

    And this variant doesn’t work ..

    
    <img src=#{PhotoAttachment.find_by_place_id(item.id).public_filename(:thumb)}
    

    Where item is the ‘result’ object passed into the partial, which infact is a ‘Place’ object.

    Thanks, Attila

  • Attila on 28 Jul 22:57

    As luck would have it … found the problem with the partial. I wasn’t allowing for nil relationships, i.e. some places didn’t have photos !!!. Bit of error checking and it works now :0)

    Cheers, Attila

  • coco on 04 Aug 04:48

    Really great, but it seems to me that the solution doesn’t work that easy for beginners.

    It seems that at some point, the accuracy about where to place snippets (in terms of files) ain’t that heavy.

    Anyway, ‘ll figure out, might also be completed in the others comments.

    In the end, it has to be said that your solution might be the best around to deal with file upload, so great thanks !!!

  • Oli on 08 Aug 01:52

    If you get an error like:

    “Validation failed: Size is not included in the list”

    try adding a minium size to has_attachment in your model

    :size => 0.kilobytes..1000.kilobytes

  • BC on 08 Aug 23:20

    Works like a charm with IE and FF but fails with Safari (tested with beta version of Safari on Windows). Mongrel says (the same with Webrick) : + 406 Not Acceptable + EOFError: bad content body IMHO Safari doesn’t like the JS answer for an upload via iframe. Is there someone who has the same problem with Safari ?

  • Khamsouk Souvanlasy on 08 Aug 23:54

    I just tried out the example on Safari on Mac and there doesn’t seem to be any problems. I don’t have a windows environment handy right now so if anyone can confirm I’ll take a closer look.

  • BC on 09 Aug 01:10

    An example : Log output (Mongrel on Linux/Debian) : http://tinyurl.com/3xm3km with Safari (Windows Version 3.0.3 (522.15.5)

    I’ve forgotten to tell you that your solution is really great ! Thanx for your article.

  • Pablo on 09 Aug 03:10

    Great tutorial!

    I can’t wait for your polymorphic attachments article.

  • mustafa ekim on 20 Aug 05:50

    say a user uploaded many images, meanwhile, attachment_fu created thumbnails for these images. how will the user see the thumbnails of the images he uploaded?

    user has_many images image has_attachment

    I need to show first the thumbnails of the images uploaded. my problem is here, user.images returns me the orijinal images but I need the thumbnails.

    how can I solve that? I should not do recursive SQLs like first finding the images that findind the thumbnails for each images …

    thanks in advance

  • Joseariel on 25 Aug 07:43

    Hello, first of all thank you for the tutorial.

    I’ve been having a problem I can’t figure out. For some reason when I upload a file, attachment_fu created 2 thumbnail successfully (profile and thumnb), but it doesn’t resize them to their respective sizes. Im using the MiniMagic as the processor. I don’t know if I should also install Rmagick to be able to resize or if that functionality comes with mini magick. Also when in I go to Localhost:3000/assets, only the original file is displayed and not the thumbnails.

  • Erik on 01 Sep 18:15

    Joseariel, when I followed the tutorial, I had the same problem. IIRC, the problem was that MiniMagick was trying to run ImageMagick’s ‘mogrify’ command, and was failing, but wasn’t giving me any information about the failure. If I were you, I would try to figure out what command MiniMagick is running, and then see what happens when you run the same command by hand. Good luck!

  • aaron on 08 Sep 09:03

    Has anyone had success with displaying a spinner (in-progress indicator) while the file is being uploaded?

    If so, would be so kind as to show your additions?

    thanks in advance,

    aaron

  • Mike on 16 Sep 23:16

    Great tutorial – one question though: what would I have to do to get my rest-less controller do treat the upload as an AJAX request? Simply adding .js to the action doesn’t do it …

  • Yuval on 04 Oct 03:30

    Have any of you guys succeeded in writing functional tests for this? I’m having the hardest time getting something working.

    My case is basically as above, posting a form to an iFrame. My controller code does its business then redirects back to the view page for the created item:

    responds_to_parent do redirect_to :action => “view” end

    Any help appreciated. Cheers.

  • John on 08 Oct 09:14

    @aaron

    You could put an “onclick” event on your submit button, and then in your controller, or your rjs template put a snippet of js to remove the “spinner”. That’s what I’m doing and it works pretty well. You could even have it fade out using RJS if you were so inclined

  • minstrel on 10 Oct 15:10

    Great tutorial!

  • felix on 11 Oct 22:59

    i try to implement your file uploading in ajax format.but it didn’t work,it show the error wrong no of arguments

  • marc on 12 Oct 06:14

    entrepreneur? you can’t even spell entrepreneuer ;-)

  • Jer on 26 Oct 12:47

    @ Erik

    What is a workaround to making Mini Magick resize the images ?

    Thanks

  • Alejandro paz on 17 Nov 11:45

    Hi, thanks for this great tutorial, it helped me tons, even i didn’t used the thumbnail section, just adapted for files to a database.

  • Chuong Huynh on 26 Nov 18:06

    Hi,

    I came accross your blog, and it extremely helpful in one of my project.

    Then come to a new one, and I really have difficulty implementing it:

    - I have a normal form. When submit the form we redirect to list screen - Within the form I have some upload controls which I want to Ajax submit them.

    The problem here is that if I set target to the tiny iframe, then the normal submit would not work like it should be: the output is directed to the iframe, and the whole page look unchanged.

    Do you have any suggestion on how to handle this case? I’ve thought of a few solutions but haven’t tried yet: onclick button to set the target attribute for the form; use rjs to simulate and redirect and use replace the whole page…

  • Craig Ambrose on 27 Nov 13:52

    Hi Khamsouk, this is one of the nicest blog posts I’ve found on this subject. I’m trying to figure out if we’ve actually met, I was at the Melbourne ruby group last week, and at railscamp. Do you head along to those sort of things?

    anyway, keep up the great work

    Craig

  • Khamsouk Souvanlasy on 27 Nov 14:55

    Hi Craig,

    Haven’t met before, but I’m a real fan of your blog and work! Melbourne is a small place and actually I think we’re one one degree away through some of the Thoughtworks guys.

    I’ve been so busy these past few months on a couple of big projects so I’ve unfortunately not had the time to come to any Rails meets or update my blog.

    Kam

  • Josh on 30 Nov 01:55

    If you get an error “undefined method `content_type’” on step 5, just continue to step 6.

    Works great, thanks for writing this up.

  • John on 30 Nov 06:03

    Looks like sean treadyway’s plugin can no longer be found at the above location. I have been unable to locate the plugin to install. Any help would be appreciated! Thanx!.

  • Khamsouk Souvanlasy on 12 Dec 15:21

    @John, responds_to_parent is a part of the download for my example application. But the actual location has moved

  • Peter Marks on 14 Dec 05:06

    @John

    try:

    script/plugin install http://responds-to-parent.googlecode.com/svn/trunk

  • Ryan Sokol on 16 Dec 08:44

    Has anyone run into this issue when using ImageScience? I’ve searched for a work around on the information super highway, but to no avail.

    [BUG] Bus Error ruby 1.8.6 (2007-03-13) [i686-darwin8.10.3]

    It stems from the call here

    module ClassMethods # Yields a block containing an RMagick Image for the given binary data. def with_image(file, &block) ::ImageScience.with_image file, &block end end

  • Ryan Sokol on 16 Dec 08:51

    Hey Me, you fixed it by the lamest of methods, rebooting my machine. Sucks but true.

  • Jer on 11 Jan 09:33

    If I want to display 2 items on the same row using a join to assets table, how can I represent public_filename for the 2 columns.

    ie/ when I use select puclic_filename, o_public_filename from …

    I get an error saying the o_public_filename is not recognized.

    Thanks in advance!!

  • Jer on 11 Jan 09:35

    If I want to display 2 seperate images on the same row using a join to assets table, how can I represent public_filename for the 2 items ?

    ie/ when I use:

    select a.public_filename, b.public_filename o_public_filename from < sql a > , < sql b> ...

    I get an error saying the o_public_filename is not recognized.

    Thanks in advance!!

  • Eric on 15 Jan 02:41

    How to display an ajax activity indicator during the file upload? It looks like the ‘loading’ & ‘success’ callbacks of the ajax request are not executed.

    Thanks, Eric

  • Glenn on 25 Jan 05:22

    Thank you so much for this blog post. I was able to take your advice and use it in my project immediately and without unwanted surprises.

  • Yojik on 29 Jan 16:31

    Has anyone write functional tests for this? I would be very appreciative for any help. Or tutorial. Or anything.

    Sorry for my English. :)

  • klmn on 13 Feb 11:05

    Hi guys,

    this is my first time dealing with mini_magick. Example from this page works for me almost fine, however I don’t understand why all my pictures get uploaded into /public/assets/0000/{asset_id}/{asset}

    I’d like to get rid of the 0000 folder..

    any thoughts would be appreciated..

    thanks, klmn

  • jujudellago on 16 Feb 10:49

    superb tutorial !

    I just had a weird issue, I had a “406 Not Acceptable” error too.

    simpified a bit the controller code to remove the respond_to do |format| ,

    so I just have

    if @photo.save flash[:notice] = ‘Photo was successfully created.’ responds_to_parent do render :update do |page| page.insert_html …..

    and now it works

    also for the destroy, I first forgot to add the format.js in the respond_to (might be useful to someone)

    just creatig the destroy.rjs is not enough…

    anyway, works great, and I really prefer that a LOT to the swfuploader, with all the setups, callbacks, flash fix & all… (I hate flash)

  • Oddmachine on 22 Feb 13:21

    Thanks so much! saved me hours and hours of time!

  • Di Marcello on 28 Feb 03:26

    i saw the formatted_*_path method here…

    but i have nested routes, where in i create the assets.

    now i can’t get the formatted_path to work for a nested resource. anyone an idea?

  • Sandy on 01 Mar 18:35

    i recieved this error undefined method `size=’ for #<photo:0x4727b04> RAILS_ROOT: ./script/../config/..

    Application Trace | Framework Trace | Full Trace C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1857:in `method_missing’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:344:in `set_size_from_temp_path’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:295:in `valid?’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:751:in `save_without_transactions’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ #{RAILS_ROOT}/app/controllers/test_upload_images_controller.rb:29:in `create’ -e:2:in `load’ -e:2

    what will be exactly reason for this one? pls help me

  • Sandy on 01 Mar 20:25

    I solved last error by adding field in table…but now i got another error

    ImageMagick command (identify C:/DOCUME1/ADMINI1/LOCALS1/Temp/minimagic4892-0 ) failed: Error Given 256

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:98:in `run_command’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:55:in `initialize’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `new’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `from_blob’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:43:in `from_file’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `open’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `from_file’

    {RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:15:in `with_image’

    {RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:322:in `with_image’

    {RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:30:in `process_attachment’

    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:301:in `valid?’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:751:in `save_without_transactions’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ #{RAILS_ROOT}/app/controllers/test_upload_images_controller.rb:30:in `create’ -e:2:in `load’ -e:2 #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:98:in `run_command’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:55:in `initialize’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `new’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `from_blob’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:43:in `from_file’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `open’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `from_file’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:15:in `with_image’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:322:in `with_image’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:30:in `process_attachment’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:301:in `valid?’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:751:in `save_without_transactions’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `perform_action_without_filters’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call_filter’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue’ C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in `perform_action’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `process_without_filters’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process_without_session_management_support’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `synchronize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ script/server:3 #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:98:in `run_command’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:55:in `initialize’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `new’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `from_blob’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:43:in `from_file’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `open’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `from_file’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:15:in `with_image’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:322:in `with_image’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:30:in `process_attachment’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:301:in `valid?’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:751:in `save_without_transactions’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ #{RAILS_ROOT}/app/controllers/test_upload_images_controller.rb:30:in `create’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `perform_action_without_filters’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call_filter’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue’ C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in `perform_action’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `process_without_filters’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process_without_session_management_support’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `synchronize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ script/server:3 -e:2:in `load’ -e:2 Request Parameters: {“photo”=>{“uploaded_data”=>#<file:c: />1/ADMINI1/LOCALS1/Temp/CGI4892-3>}, “commit”=>”Upload”}

    this error irritating me every time every i used set processor as mini magick

    what will be solution, 10x in advance :)

  • sandy on 01 Mar 20:28

    Sorry the actual error is

    ImageMagick command (identify C:/DOCUME1/ADMINI1/LOCALS1/Temp/minimagic4892-0 ) failed: Error Given 256

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:98:in `run_command’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:55:in `initialize’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `new’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `from_blob’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:43:in `from_file’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `open’

    {RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `from_file’

    {RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:15:in `with_image’

    {RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:322:in `with_image’

    {RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:30:in `process_attachment’

    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:301:in `valid?’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:751:in `save_without_transactions’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ #{RAILS_ROOT}/app/controllers/test_upload_images_controller.rb:30:in `create’ -e:2:in `load’ -e:2 #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:98:in `run_command’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:55:in `initialize’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `new’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `from_blob’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:43:in `from_file’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `open’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `from_file’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:15:in `with_image’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:322:in `with_image’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:30:in `process_attachment’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:301:in `valid?’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:751:in `save_without_transactions’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `perform_action_without_filters’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call_filter’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue’ C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in `perform_action’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `process_without_filters’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process_without_session_management_support’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `synchronize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ script/server:3 #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:98:in `run_command’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:55:in `initialize’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `new’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:37:in `from_blob’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:43:in `from_file’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `open’ #{RAILS_ROOT}/vendor/plugins/mini_magick/lib/mini_magick.rb:42:in `from_file’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:15:in `with_image’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:322:in `with_image’ #{RAILS_ROOT}/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:30:in `process_attachment’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:333:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:330:in `callback’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:301:in `valid?’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:751:in `save_without_transactions’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save’ #{RAILS_ROOT}/app/controllers/test_upload_images_controller.rb:30:in `create’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `perform_action_without_filters’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call_filter’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue’ C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in `perform_action’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `process_without_filters’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process_without_session_management_support’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `synchronize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ script/server:3 -e:2:in `load’ -e:2 Request Parameters: {“photo”=>{“uploaded_data”=>#<file:c: />1/ADMINI1/LOCALS1/Temp/CGI4892-3>}, “commit”=>”Upload”}

  • Matt on 15 Mar 07:58

    Sandy, how did you solve the undefined method `size=’ error? You say you solved it by “adding field in table” – what do you mean by that?

  • Ianthps on 25 Mar 01:55

    thanks much, brother

  • John Devine on 01 Apr 13:32

    I’m trying this out now, and there’s one thing I’m not getting. In the controller, I’m always hitting the respond_to.html block, instead of the desired respond_to.js block. Is there something in this that should be telling the controller to consider this request a javascript request, event though it’s no longer coming though javascript?

  • John Devine on 01 Apr 13:50

    One solution to my problem outlined above:

    in the “remote” form, include a hidden input with the name “format” and the value “js”.

    To explain, line 117 of mime_responds.rb reads:

    @mime_type_priority = Array(Mime::Type.lookup_by_extension(@request.parameters[:format]) || @request.accepts)

    which mean you can override the “request.accepts”, and fool your controller into thinking it’s dealing with a different mime-type without messing with headers. Glad they thought of that.

  • Bhushan Ahire on 01 Apr 15:55

    [:re] Works like a charm with IE and FF but fails with Safari (tested with beta version of Safari on Windows). Mongrel says (the same with Webrick) : + 406 Not Acceptable + EOFError: bad content body IMHO Safari doesn’t like the JS answer for an upload via iframe. Is there someone who has the same problem with Safari ?

    I got this error, most probably when you upload an flash (.flv) video then from safari its not able to get the content type of video file so get an error as

    NoMethodError (undefined method `content_type’ for #<string:0xb644adac>):

    This issue is with the attachment_fu plugin.

    Do you know whats an issue, or do you have any other workaround for this let me know if you have, please send to my mail id also.

  • Adhiraj on 09 Apr 17:40

    Does it work with Rails 1.2.3? If yes, please guide me with the steps to get it working.

  • Santh on 11 Apr 00:19

    thanks it is a good tutorial But i was confused regarding restful

    If it the restful fileupload or not?

  • Yuval on 21 Apr 05:42

    I’ve encountered a pretty big bug with iFrame remoting and Safari 3.1. Specifically, Safari loses its mind when there’s an iFrame on the page. It goes like this:

    1) Update an element on the page via ajax (remote_form_for, link_to_remote, etc). 2) Navigate away from the page. 3) Click back 4) Notice that the element has reverted to its original state.

    Safari caches the page when an iFrame is present, and thus far I haven’t figured out how to prevent it from doing so.

    :(

  • Doesn't Work on 25 Apr 02:18

    Doesn’t work. My code fails with:

    undefined method `assets_path’ for #<#<class:0x35d43ac>:0×35d4370>

    or

    undefined method `asset_path’ for #<#<class:0x35d43ac>:0×35d4370>

    There’s really no way of knowing what Class it’s referring to. And I can’t find the string “asset_path” anywhere in the code base. I guess it’s one of those Rails-generated mysteries that I’ll never be able to solve.

    So, 8 hours later, nothing. The downloadable example works fine, but I can’t figure out why.

  • Ravikumar on 25 Apr 21:48

    Hi, I implemented photo upload using iframes and responds_to_parent concept its working fine in Mozilla and IE but it is not working in Safari(pop window is open and it will close immediately). Please let me know what i did mistake. Actually my requirement is using AJAX call i need to upload photo,but i tried i am getting “content_type” error (multipart => true is sited).

    Please help me on the above issue.

    thanks Ravi

  • Matthew on 01 May 03:20

    Thanks for the post kam, didn’t have a single snag implementing this on my rails app.

    @Doesn’t Work

    You need to define the rails route, in your routes.rb add:

    map.resources :assets

    assets_path and asset_path are helpers automatically generated by the routes.

    Hope that helps :)

    @Ravikumar

    It works fine for me on Safari.

  • Pete on 23 May 18:48

    This looks like a cracking tutorial. I havent read it all yet, just popped in for the download method but that works perfectly, thanks.

    Rest assured i will be back to read the rest of this tutorial very soon.

    Peace

  • Pete on 23 May 18:54

    This looks like a cracking tutorial. I havent read it all yet, just popped in for the download method but that works perfectly, thanks.

    Rest assured i will be back to read the rest of this tutorial very soon.

    Peace

  • Jason on 22 Jun 11:03

    This is just what I needed! Thanks for the great write-up. Probably saved me hours of IFRAME/JS hacking.

  • kamil on 27 Jun 00:43

    Thanks! It’s perfect.

  • Daniel on 27 Jun 01:24

    I love this idea, and it works great. The problem is, who wants to upload one file at a time any more? Most people have two or three files that they need to push up to a site, and waiting for one to upload, then adding another sometimes isn’t the right solution.

    My Idea:

    Render multiple upload forms, each with a unique DOM name. Then use a little javascript to submit all the forms at once, giving the illusion of all the uploads being sent in the same form.

    Thoughs??

  • volks on 05 Jul 12:27

    any idea why this would occur?

    Mysql::Error: Table ‘test2_development.db_files’ doesn’t exist: SHOW FIELDS FROM db_files

    Thanks

  • volks on 05 Jul 14:54

    hi,

    if i use :thumb in the asset link to display the thumb nails on index.rhtml the images wont show, for some reason they are getting saved to the public/assets folder with their original names.

    Any idea how i can solve this?

    Thanks in Advance

  • coops on 30 Jul 17:10

    Ok i am using the most current ruby on rails and for some reason.. none of this is working for me.. have tried to implement this into my current app and is going no were… expect i don’t want to use frames i want to use partials and want to be able to use the same functionality as you would with a ajax text field that you add a file then it refreshs the partial to show the current files.. etc etc

    any help?

  • Marco on 02 Sep 02:01

    I’ve to edit the attachment_fu.rb because it don’t retrive size even specifing :size => 0..5000.kilobytes and if i start from 1 it gives me the message: “Validation failed: Size is not included in the list”

    My changes:
    1. Returns true if the attachment data will be really written to the storage system on the next save def save_attachment? 10.times do if File.file?(temp_path.to_s) && File.size(temp_path) > 0 return true end sleep 1 end false end
  • Scott on 10 Sep 12:38

    I am trying to modify these instructions to my existing database. I am using Instant Rails 2.0 and SQLite to build my database. I don’t get any page loading errors, but rails does not recognize the imagemagik command. I get “Exception working with image: ImageMagick command (identify “C:/.../Local/Temp/minimagick4920-0”) failed: Error Given. Thos only happens when I hit the create button. However, the minimagick4920-0 is located in that directory. I am about a month into rails. Any suggestions?

  • pfepup on 21 Oct 22:55

    Dont get. As he grunted, and naked celebrities i get to.

  • carlo on 22 Oct 20:04

    Bummer the dreaded Security upgrades to prevent cross-scripting are making iframe based respond_to_parent not work because Mozilla and others now give permission exceptions when an outside script tries to access another window from the iframe using window.parent or any such function.

    see the Mozilla bug at: https://bugzilla.mozilla.org/show_bug.cgi?id=397828

    Does anyone know of a workaround for this ?

  • Ficafloapslop on 30 Oct 05:18

    Eh.. I want you to respond well to my murky armpit I have a nice joke. What do fish play on the piano? Scales.

  • hemanth on 30 Oct 18:12

    Hi,

    Does this work in a scenario where i have to post a file to a REST server in rails and the client is Ajax or php.

  • Rainer on 02 Dec 08:25

    I tried to implement this. The file upload works, but I get the following error in Safari (current OS X, current Rails 2.2.2)

    RJS error:

    TypeError: Value undefined (result of expression Element.insert) is not object.

    Anyone knows what this is about

  • Curt on 29 Dec 15:11

    I’m getting the same error that Rainer is reporting.

  • Daniel on 12 Jan 12:05

    I’ve posted a demo on how to apply this to multiple file fields. Check it out at http://prowestech.com/posts/4

  • poka on 26 Jan 23:47

    I have got this eoor: “Validation failed: Size is not included in the list”. If I try to upload a file sizes more than 19KB then I gets that eoor. Now If I comment validates_as_attachment then I can upload image of any sizes by using the :size variable. But here I get a new problem.In this condition if I want to upload a big sizes image then then 0 size is stored in the mysql database. Thanks for any help.

  • Richard on 04 Feb 13:10

    Curt and Rainer, I had the same problem but solved it using the latest versions of prototype and scriptaculous. I have also heard of people having problems when they forgot to add the js files… Cheers

  • Guy Boertje on 12 Feb 02:49

    I have blogged about using LiveQuery in the main document to take (some of) the response from the child iframe and put it into the main doc somewhere.

    http://rails-revlog.blogspot.com/2009/02/ajax-sort-of-file-upload-using.html

    This method does not need rjs or the responds to parent plugin. You just need to return some html and your live query function can select the node in the iframe body and copy that into your main doc.

  • MataArcar on 06 Mar 14:32

  • EuroffTus on 21 Mar 21:50

    tfggvg%$j**jk , http://www.simteach.com/wiki/index.php?title=User:Buy_aciphex&oldid=9219#1 aciphex, 33201 , http://www.simteach.com/wiki/index.php?title=User:Buy_acomplia&oldid=9221#1 buy acomplia, treomb , http://www.simteach.com/wiki/index.php?title=User:Buy_allegra&oldid=9223#1 buy allegra, jjbvc , http://www.simteach.com/wiki/index.php?title=User:Buy_allopurinol&oldid=9225#1 Buy allopurinol, jhgtiop , http://www.simteach.com/wiki/index.php?title=User:Buy_avapro&oldid=9227#1 150 avapro mg, 261kjhj ku624, http://www.simteach.com/wiki/index.php?title=User:Buy_adalat&oldid=9229#1 buy Nifedipine, kii8 , http://www.simteach.com/wiki/index.php?title=User:Buy_amoxil&oldid=9231#1 amoxil 500mg, :) , http://www.simteach.com/wiki/index.php?title=User:Buy_amoxicillin&oldid=9233#1 buy amoxicillin

  • Kosikdr on 24 Mar 22:53

    I have very strong feelings about how you lead your life. You always look ahead, you never look back. http://esqotiwis.ifrance.com/shemale-slave.html – shemale slave http://esqotiwis.ifrance.com/free-lesbian-sex-chat-rooms.html – free lesbian sex chat rooms

  • Steve Abrams on 19 Jun 06:41

    Thanks for your post! This was very helpful.

Post a comment

Thanks for the comment!