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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:29:31+00:00 2026-05-13T20:29:31+00:00

I changed my photo.rb model to be polymorphic and be usable to all sorts

  • 0

I changed my photo.rb model to be polymorphic and be usable to all sorts of other models needing to save images and it works fine except I can’t figure out how to save new attachments properly through the parent model. Any ideas? Do I have to approach this differently somehow? As, its also not getting the imageable_type…which i’ll have to add.

I saw the polymorphic paperclip plugin which looks like a beast and uses yet another table? So I’m hoping for a better work around.

I’m getting:

ActiveRecord::AssociationTypeMismatch (Photo(#2189565500) expected, got Array(#2148226700))

Parameters: {"commit"=>"Create", "action"=>"update", "_method"=>"put", "authenticity_token"=>"kp7NeMs7moGwu0AZMXVowUpphp9vzitdZZ6t8YO7RKQ=", "id"=>"2586", "muffin"=>{"photos"=>{"data"=>#<File:/var/folders/4d/4dqp9CQQEbmM1akqbtLxzk+++TI/-Tmp-/RackMultipart20100218-11622-onqem2-0>}}, "controller"=>"muffins"}

muffin.rb

has_many :photos, :as => :imageable, :dependent => :destroy

photo.rb

belongs_to :imageable, :polymorphic => true
has_attached_file :data,
    :storage => 's3',
    :s3_credentials.....
  • 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-13T20:29:31+00:00Added an answer on May 13, 2026 at 8:29 pm

    I got the idea to use accepts_nested_attributes_for since that’s what I might do if it wasn’t a polymorphic association but another model i was throwing attributes at.. and voila, it worked.

      has_many :photos, :as => :imageable, :dependent => :destroy
      accepts_nested_attributes_for :photos
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I changed the folder that my WordPress installation was in. However, this worked fine,
I changed the file permissions on all my files and directories in my Joomla
I have a model like this: class Entity(models.Model): entity_name = models.CharField(max_length=100) entity_id = models.CharField(max_length=30,
In a new MVC application, I am building out all of the models, controllers,
I made a networked game in Java using Sockets. It works great, except... only
I have an Article model and a Photo model, and I am currently using
I have Picture model it contain 2 fields photo and description (photo is field
I have a photo rails app using paperclip. My model called photo and the
I have a Gallery application that has Album and Photo models. I have the
I changed my .autotest file to use it with a Ruby-based project. After that,

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.