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 946481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:55:24+00:00 2026-05-15T22:55:24+00:00

What I have is a Theme model, which contains many Assets. Assets are using

  • 0

What I have is a Theme model, which contains many Assets. Assets are using Paperclip and storing their file content in my Amazon AWS-S3 system. I’m also using deep_clone because my customers have the ability to copy built in Themes and then modify them to their hearts content. All the deep_clone stuff is working great, but when I deep_clone the assets, the old file contents don’t get added to my S3 buckets. The record gets saved to the database, but since the file-contents don’t get saved with the new ID the file.url property points to a dead file.

I’ve tried calling paperclip’s save and create method manually but I can’t figure out how to get paperclip to “push” the file back to the bucket since it now has a new ID, etc….

require 'open-uri'

class Asset < ActiveRecord::Base
  belongs_to :theme
  attr_accessor :old_id
  has_attached_file :file,
                    :storage => "s3",
                    :s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/aws.yml")[RAILS_ENV],
                    :bucket => "flavorpulse-" + RAILS_ENV,
                    :path => ":class/:id/:style.:extension"
  validates_attachment_presence :file
  validates_attachment_size :file, :less_than => 5.megabytes

  before_save :delete_assets_in_same_theme_with_same_name
  after_create :copy_from_cloned_asset

  private
  def delete_assets_in_same_theme_with_same_name
    Asset.destroy_all({:theme_id => self.theme_id, :file_file_name => self.file_file_name})
  end

  def copy_from_cloned_asset
    if (!old_id.blank?)
      if (old_id > 0)
        old_asset = Asset.find(old_id)
        if (!old_asset.blank?)
          self.file = do_download_remote_image(old_asset.file.url)
          self.file.save
        end
      end
    end
  end

  def do_download_remote_image (image_url)
    io = open(URI.parse(image_url))
    def io.original_filename; base_uri.path.split('/').last; end
    io.original_filename.blank? ? nil : io
  rescue # catch url errors with validations instead of exceptions (Errno::ENOENT, OpenURI::HTTPError, etc...)
  end
end

Any ideas on how I can get paperclip to push the file? I also wouldn’t be opposed to doing this using Amazon’s aws-s3 gem but I couldn’t seem to get that to work either.

  • 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-05-15T22:55:25+00:00Added an answer on May 15, 2026 at 10:55 pm

    According to this former question/answer, it should be possible with this simple line of code:

    self.file = old_asset.file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a Book model, which contains many Page models. The routing for
I have a model which contains many predefined rows (> 100) and also can
I have a wicket form which contains many TextField input components. There's a Validator
I have a model which contains a ManyToMany to User to keep track of
I have the $validate variable in my model which contains: var $validate=array( username =>
I have these a coffeescript file for a model entree that just instanciates a
I want to generate a list using my django model say I have these
I have a notifications table which contains different types of notifications for different events.
My application is structured like this: There is a Sidebar which contains many items
I am working on a Rail webapp. I have two models, User, which contains

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.