You could create a function that gets the size of the array, loops through it and creating a return array which it returns.

Concise vector adding in Python?
I am using tinymce-rails-imageupload plugin with dragonfly.

When the image is uploaded via separate form in popup window, it behaves as expected (save image in datastore). 

But when the user drag-drop or paste image into TinyMCE, the imageupload plugin allows it. I tried to find a way to disable this behavior, but apparently there is no straightforward way to disable allowing image upload, while disallowing the past/drag-drop behavior. So I gave up on that..

Now, I'm trying to save BASE64 image in TinyMCE's content.

In controller:

def store_file
  @image = Resource.new :res_image =&gt; params[:file]
  @image.save
  render json: {
    image: {
      url: @image.res_image.remote_url
    }
  }, content_type: "text/html"
end

def create
  @entry = Entry.new(params[:entry])

  # iterate through tinyMCE field params[:entry][:message]
    # if image tag is found
      # if value of src tag starts with "data:"
        # then replace it with the output of
        # Resource.create_image_from_base64(extracted_base64_value)
      # end if
    # end if
  # end iteration

  begin
    @entry.save!
    flash[:success] = "Entry was successfully created."
    redirect_to entries_path
  rescue Mongoid::Errors::Validations =&gt; e
    render :action =&gt; "new"
  end
end


In Resource model, I would have something like:

image_accessor :res_image

field :res_image_uid,      type: String
field :res_image_name,     type: String

def create_image_from_base64(base_64_encoded_data)
  file = File.open('temp.png', 'wb') do|f|
   f.write(Base64.decode64(base_64_encoded_data))
  end

  resource = # create Resource with temp file

  file.close

  resource.res_image.remote_url
end


Questions:


How to create "Entry with file"?
Is there a better approach for handling pasted/dragged-droped base64 images in TinyMCE with dragonfly?

