AJAX file uploads in Rails using attachment_fu and responds_to_parent
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:
- 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.
- acts_as_attachment – written by Rick Olson, it does everything that file_column can, but with a cleaner and extensible code base.
- 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:- 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.
- 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.
- 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).
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:imageto allow all standard image types.min_size– Minimum size allowed. 1 byte is the default.max_size– Maximum size allowed. 1.megabyteis the default.size– Range of sizes allowed. (1..1.megabyte) is the default. This overrides the:min_sizeand:max_sizeoptions.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. Usespublic/#{table_name}by default for the filesystem, and just#{table_name}for the S3 backend. Setting this sets the:storageto:file_system.storage– Use:file_systemto 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 yourroutes.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
-
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
-
dazza, you need to add the following line in routes.rb:
map.resources :assetsThis should already have been added to routes.rb with the command:
ruby script/generate scaffold_resource ...in step 4.
-
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)
-
Thanks for this tut. Will it work with lighttpd?
-
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)
-
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.
-
Any chance you could post a link to a live app so we can see what the end-result should look like?
-
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?
-
That would be stellar!
-
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.
-
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?"%>)
-
A download of the example code can be found here
-
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. :(
-
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.
-
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.
-
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.
-
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.
-
(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.
-
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.
-
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
-
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
-
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
-
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?
-
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.
-
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!
-
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
-
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.
-
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
-
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!
-
@Chirag Patel,
If you look at the Attachment_fu readme it gives the example, “has_attachment :content_type => [‘application/pdf’, ‘application/msword’, ‘text/plain’]”
-
@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.
-
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 -
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.
-
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
-
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
-
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
-
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
-
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
-
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 !!!
-
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
-
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 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.
-
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.
-
Great tutorial!
I can’t wait for your polymorphic attachments article.
-
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
-
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.
-
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!
-
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
-
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 …
-
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.
-
@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
-
Great tutorial!
-
i try to implement your file uploading in ajax format.but it didn’t work,it show the error wrong no of arguments
-
entrepreneur? you can’t even spell entrepreneuer ;-)
-
@ Erik
What is a workaround to making Mini Magick resize the images ?
Thanks
-
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.
-
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…
-
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
-
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
-
If you get an error “undefined method `content_type’” on step 5, just continue to step 6.
Works great, thanks for writing this up.
-
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!.
-
@John, responds_to_parent is a part of the download for my example application. But the actual location has moved
-
@John
try:
script/plugin install http://responds-to-parent.googlecode.com/svn/trunk
-
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
-
Hey Me, you fixed it by the lamest of methods, rebooting my machine. Sucks but true.
-
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!!
-
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!!
-
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
-
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.
-
Has anyone write functional tests for this? I would be very appreciative for any help. Or tutorial. Or anything.
Sorry for my English. :)
-
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
-
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)
-
Thanks so much! saved me hours and hours of time!
-
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?
-
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
-
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 :)
-
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”}
-
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?
-
thanks much, brother
-
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?
-
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.
-
[: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.
-
Does it work with Rails 1.2.3? If yes, please guide me with the steps to get it working.
-
thanks it is a good tutorial But i was confused regarding restful
If it the restful fileupload or not?
-
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. 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.
-
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
-
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.
-
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
-
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
-
This is just what I needed! Thanks for the great write-up. Probably saved me hours of IFRAME/JS hacking.
-
Thanks! It’s perfect.
-
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??
-
any idea why this would occur?
Mysql::Error: Table ‘test2_development.db_files’ doesn’t exist: SHOW FIELDS FROM db_files
Thanks
-
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
-
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?
-
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:- 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
-
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?
-
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 ?
-
Eh.. I want you to respond well to my murky armpit I have a nice joke. What do fish play on the piano? Scales.
-
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.
-
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
-
I’m getting the same error that Rainer is reporting.
-
I’ve posted a demo on how to apply this to multiple file fields. Check it out at http://prowestech.com/posts/4
-
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.
-
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
-
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.
-
http://mysoftlist.cn/image/casino5.gif
where to buy viagra online order viagra viagra faq uk cheapest viagra buy cheap generic viagra bob dole viagra generic mexico pharmacy viagra buy cheapest online viagra cheap pill viagra cheap foreign generic viagra buy site viagra drug erection viagra buy discount viagra online buy online viagra viagra viagra canadian pharmacy viagra 10 minute viagra cheap viagra order online cheap viagra order online cialis compare levitra performance viagra over the counter viagra viagra discount sale pharmaceutical female viagra buy viagra online without prescription non prescription viagra viagra dosages buy levitra online viagra avoid generic viagra non prescription viagra discount viagra online buy viagra canada pharmacy viagra generic viagra pharmaceutical female viagra discount viagra herbal viagra alternative review buying online risk viagra discover viagra where to buy viagra on line cheap generic viagra online canada cheap viagra best viagra deal how does viagra work buy site viagra cheap uk viagra herbal viagra alternative review cialis compare levitra viagra pc100 viagra discount viagra viagra lozenges bob dole viagra
-
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
-
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
-
Thanks for your post! This was very helpful.
Post a comment
Thanks for the comment!

