Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8156601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:00:10+00:00 2026-06-06T17:00:10+00:00

i was trying for multiple image upload with dragonfly in rails3. i searched for

  • 0

i was trying for multiple image upload with dragonfly in rails3. i searched for some tutorials, but couldn’t find any. i found a tutorial for multiple image upload with Carrierwave, but couldnt find luck with dragonfly .. any help please 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:00:13+00:00Added an answer on June 6, 2026 at 5:00 pm

    Preface

    Dragonfly itself can be used to manage media for your project in general, similar to paperclip. The question itself boils down to the multiple file upload within a rails application. The some tutorials on this topic available, which can easily be adapted to models using Dragonfly for storing specific files on them. I would suggest you look into those and try to adapt them for your project.

    However, I can present a minimum example which i built for a rails 3.2 app currently in development, which isn’t perfect (validation handling for example), but can give you some starting points.

    Example

    Just for reference, the essential idea is taken from here. This example is done with Rails 3.2.x.

    Let’s say you have a vacation database, where users may create trip reports on vacations they took. They may leave a small description, as well as some pictures.

    Start out by building a simple ActiveRecord based model for the trips, lets just call it Trip for now:

    class Trip < ActiveRecord::Base
        has_many :trip_images
        attr_accessible :description, :trip_images
    end
    

    As you can see, the model has trip images attached to it via a has_many association. Lets have a quick look at the TripImage model, which uses dragonfly for having the file stored in the content field:

    class TripImage < ActiveRecord::Base
        attr_accessible :content, :trip_id
        belongs_to :trip_id
    
        image_accessor :content
    end
    

    The trip image it self stores the file attachment. You may place any restrains within this model, e.g. file size or mime type.

    Let’s create a TripController which has a new and create action (you can generate this via scaffolding if you like, it is by far nothing fancy):

    class TripController < ApplicationController
        def new
            @trip = Trip.new
        end
    
        def create 
            @trip = Trip.new(params[:template])
    
            #create the images from the params
            unless params[:images].nil?
                params[:images].each do |image|
                @trip.trip_images << TripImages.create(:content => image)
            end
            if @trip.save
                [...] 
        end
    end
    

    Nothing special here, with the exception of creating the images from another entry than the params hash. this makes sense when looking at the the file upload field within the new.html.erb template file (or in the partial you use for the fields on the Trip model):

    [...]
    <%= f.file_field :trip_images, :name => 'images[]', :multiple => true %>
    [...]
    

    This should work for the moment, however, there are no limitations for the images on this right now. You can restrict the number of images on the server side via a custom validator on the Trip model:

    class Trip < ActiveRecord::Base
        has_many :trip_images
        attr_accessible :description, :trip_images
        validate :image_count_in_bounds, :on => :create
    
    protected
        def image_count_in_bounds
            return if trip_images.blank?
            errors.add("Only 10 images are allowed!") if trip_images.length > 10
        end
    end
    

    I leave this up to you, but you could also use client side validations on the file field, the general idea would be to check the files upon changing the file field (in CoffeeScript):

    jQuery ->
        $('#file_field_id').change () ->
             #disable the form
             for file in this.files
                 #check each file  
             #enable the form
    

    Summary

    You can build a lot out of existing tutorials, as dragonfly does not behave that differently to other solutions when it comes to just to uploading files. However, if you’d like something fancier, I’d suggest jQuery Fileupload, as many others have before me.

    Anyways, I hope I could provide some insight.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to save multiple image using this code. But instead its saving
I am trying to upload multiple files but when i select more than 1
I am trying to upload some files using the multiple upload file field. The
i'm trying to allow user to upload multiple images but when i validate the
I'm trying to upload multiple files via a form, but I can only upload
I'm trying to upload some videos using PHP. But I can't get them into
I'm trying to upload multiple files at once with Play Framework, but I always
I am trying to upload multiple images and I have a jquery plugin set
I am trying to create a multiple image uploader and I have come across
I am trying to create a universal image selector for multiple buttons. Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.