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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:06:06+00:00 2026-05-16T10:06:06+00:00

I’m using paperclip for attachments for multiple models using accepts_nested_attributes_for. Is there a way

  • 0

I’m using paperclip for attachments for multiple models using accepts_nested_attributes_for. Is there a way I can specify specific paperclip style options for each model?

  • 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-16T10:06:07+00:00Added an answer on May 16, 2026 at 10:06 am

    Yes. I use single table inheritance (STI) on sites for handling Audio, Video, and Images via an Asset model.

    # models/Asset.rb
    class Asset < ActiveRecord::Base
      # Asset has to exist as a model in order to provide inheritance
      # It can't just be a table in the db like in HABTM. 
    end
    
    # models/Audio.rb
    class Audio < Asset # !note inheritance from Asset rather than AR!
      # I only ever need the original file
      has_attached_file :file
    end
    
    # models/Video.rb
    class Video < Asset
      has_attached_file :file, 
        :styles => {
          :thumbnail => '180x180',
          :ipod => ['320x480', :mp4]
          },
        :processors => "video_thumbnail"
    end
    
    # models/Image.rb
    class Image < Asset
      has_attached_file :file,
        :styles => {
          :medium => "300x300>", 
          :small => "150x150>",
          :thumb => "40x40>",
          :bigthumb => "60x60>"
        }
    end
    

    They all come into Rails as :file, but the controller (A/V/I) knows to save to the proper model. Just remember that all attributes for any of the forms of media need to be included in Asset: if video doesn’t need captions but images do, then the caption attribute will be nil for Video. It won’t complain.

    Associations will also work fine if hooked up to the STI models. User has_many :videos will operate the same as you are using it now, just make sure you don’t try to save to Asset directly.

      # controllers/images_controller.rb
      def create
        # params[:image][:file] ~= Image has_attached_file :file
        @upload = current_user.images.build(params[:image]) 
        # ...
      end
    

    Lastly, since you do have an Asset model, you can still read directly from it if e.g. you want a list of the 20 most recent Assets. Also, this example isn’t restricted to separating media types, it can be used for different kinds of the same thing as well: Avatar < Asset, Gallery < Asset, and so on.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am using Paperclip to handle profile photo uploads in my app. They upload
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.