Image upload in rails - ruby-on-rails

How do I upload images and zip files in RoR? I am a newbie. So please help.
Give me both the view and the controller code example.
Thanks in advance.

Nav,
Try the paperclip plugin, you can read about it here http://www.thoughtbot.com/projects/paperclip

We prefer CarrierWave for image uploads in Rails. Very easy to integrate and very modular.
The following post describes a solution for image uploading using CarrierWave while image transformations are done seamlessly in the cloud. Uploaded images are stored in the cloud and delivered through a CDN.
No need to install RMagick, MiniMagick and ImageMagick.
http://cloudinary.com/blog/ruby_on_rails_image_uploads_with_carrierwave_and_cloudinary

suggest checking out the Railscast for paperclip.

ImageMagick is also pretty cool

I would recommend paperclip, and the patch that allows you to store the content in the database instead of the file system
http://patshaughnessy.net/paperclip-database-storage
the link has the view and controller examples that you are looking for

I prefer carrierwave is better to upload images easily.
Here's github page , and railscasts page for quick start.

One option is attachment_fu. It allows you to save your uploaded file to the filesystem, database, or Amazon S3. It also allows you to select which image processor is used, such as RMagick or Minimagick.
The link provides better code than I could here.

Related

Cloudinary with rails won't show my picture

I am developing a Rails application and I want to upload a picture directly from my browser using Cloudinary.
I followed all steps from the Cloudinary page and ended up with a box and a question mark after I "uploaded" it, no picture at all. Any ideas what might be the problem?
I am not sure what you have used. But you should use carrierwave with cloudinary. Cloudinary having some complex way to handle display and save image if you don't use carrierwave.
But carreirwave provide simpler way to achieve uploading and display image.
Without using carrierwave
Using carrierwave in compbination
You should try the sample project and then check the differences:
https://github.com/cloudinary/cloudinary_gem/tree/master/samples/photo_album

Carrierwave/fog are uploading files to S3, but the app is still trying to use the local path to access images

I know this is a broad question, and I'm biting off a little more than I can chew for a first stab at a rails app, but here I am.
I tried to add an image upload/crop to a basic status app. It was working just fine uploading the images and cropping them with carrierwave, but as soon as I started using Fog to upload to S3, I ran into issues.
The image, and it's different sizes, appear to be ending up on S3 just fine, but the app is still trying to access the image as "/assets/uploads/entry/image/65/large_IMG_0035.jpg"
Locally, it just shows a broken image, but on Heroku it breaks the whole thing because
ActionView::Template::Error (uploads/entry/image/1/large_IMG_0035.jpg isn't precompiled
The heroku error makes sense to me because it shouldn't be there. I've combed through the app but don't know what's forcing this. I'll post any code anybody thinks will work? Thanks in advance!
Clarification:
Just to clarify, the images are uploading to S3 fine, the problem is how the app is trying to display the image_url
The app is using a local path in the asset pipeline, not the S3 path that it's actually uploading to.
I was having the same issue. In my Carrierwave Initializer I was setting host to s3.amazonaws.com but when I removed that line altogether urls started working.
I hope this helps you resolve your issue, I fought this for several hours!
I believe this issue is related to how you are accessing your image in your view.
If you have mounted an uploader on the field avatar in the following manner:
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
You would access it in your ERB as follows:
<%= image_tag(#user.avatar_url) %>
I would also suggest watching the following Railscast on the topic.
http://railscasts.com/episodes/253-carrierwave-file-uploads
Re-reading issue, I bet it has to do with Carrierwave using Herkou.
Give this a glance and see if it helps.
https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Make-Carrierwave-work-on-Heroku
I am not clear what exactly do you want to achieve.
But for now I have 2 ideas:
For assets host in CDN, you can take a look at this:
https://devcenter.heroku.com/articles/cdn-asset-host-rails31
If you want the images to be part of a model-relation, here's my rough idea:
Put the images path in a table column.
For further information about this you can browse carrierwave github site.(It has many docs and tutorial)

What should i use for rails file attachment and jruby?

Normally I'd use carrierwave, but they do not officially support jruby, and I've been running in to bugs, possibly related. (https://github.com/jnicklas/carrierwave/issues/620, Image corruption on upload to s3, production only. (carrierwave, engineyard))
Have others had success here?
I'm considering trying out paperclip, but it looks like that may not be perfect either-- https://github.com/thoughtbot/paperclip/issues/100
Try dragonfly it's a really great library to manage you file attachment.
check out this guide, it's cake
http://webtempest.com/how-to-allow-image-uploads-in-rails-on-heroku/
It uses paperclip and amazon web s3 gems

File uploading rails 3

I have a rails 3 app that has a comment system that allows a user to make comments. What I now wish to do is extend this further by enabling the user to attach/upload files to the comment system. Fairly easy question I am about to ask. What is the best tool/plugin or gem to use so that I can achieve this? I've done some thorough research and found that alot of these plugins such as carrierwave, paperclip and a few others are used to upload photos and I am not trying to do this.
Requirements
User should be able to upload/attach files
Can upload word, powerpoint or execel docuements
Both carrierwave and paperclip can be used to upload any type of files - they have extra features if you want to upload images, but they are not restricted to handling just image files.
In the end it's a matter of preference. I found both paperclip and carrierwave to be very good at what they do.
Paperclip
CarrierWave
As for me CarrierWave more modern and nice solution. Have a try.
You can use even dragonfly - https://github.com/markevans/dragonfly/

Rails: attachment_fu plugin, convert PDF uploads to image

Yo,
I've got attachment_fu set up on my server, and it works just fine. My goal, however, is to be able to upload PDFs and have them convert to image (then use all the pre-built attachment_fu options like resize and thumb produce the desired images). What currently happens is that PDFs upload and remain PDFs, whereas images go through all the motions of resizing and whatnot.
How can I get the functionality I want? Is there a simple way to go about doing this using the tools I already have, or should I just manually invoke RMagick to do the initial conversion? If so, how can I do that and then pass off the file to attachment_fu for handling?
Thanks,
--Matchu
For the oldest unanswered rails question: https://stackoverflow.com/a/69804/156561 his answer is probably very similar to get you in the door to use Attachment_fu which I'm sure you've by now migrated off.

Resources