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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:58:46+00:00 2026-06-12T14:58:46+00:00

Can someone please assist with regards to CarriveWave’s store_dir. How does one have mulitple

  • 0

Can someone please assist with regards to CarriveWave’s store_dir.

How does one have mulitple image models that stores files based on the associated belong_to model’s permalink?

# Garage model
class Garage < ActiveRecord:Base

  attr_accessible: :avatar, :permalink, :car_image_attributes,
                   :motorcycle_image_attributes

  has_many :car_image
  has_many :motorcycle_image

  mount_uploader :avatar, AvatarUploader

  def set_permalink
    self.permalink = permalink.parameterize
  end

  def to_param
    permalink.parameterize
  end

end

This is what my Image Models that links with CarrierWave

# Car Image model
CarImage < ActiveRecord:Base
  belongs_to :garage
  attr_accessible: :garage_id, :image

  mount_uploader :car_image, CarUploader

end

# Motocycle Image model
MotocycleImage < ActiveRecord:Base
  belongs_to :garage
  attr_accessible: :garage_id, :image

  mount_uploader :motorcycle_image, MotocycleUploader

end

This is what my CarrierWave uploaders look like.

# CarrierWave avatar uploader
avatar_uploader.rb
  # This uploader directly relates to the Garage model table 
  # column avatar:string.

  def store_dir
    # This works for the avatar because it calls on the Garage permalink
    # but it fails for the other image models because it's a model relation
    # has_many, belongs_to and the model.permalink will be based on the
    # uploader's respective model and not the Garage model
    # eg. car_uploader.rb = model.permalink = CarImage.permalink
    # I would like it to refer to to Garage.permalink at all times.
    "garage/#{model.permalink}/#{mounted_as}/"
  end
end

# CarrierWave car and motorcycle uploaders
car_uploader.rb
# Fails to upload because it doesn't know what permalink is
end

motorcycle_uploader.rb
# Fails to upload because it doesn't know what permalink is
end

Apologies if I wants so clear but a big thanks for any insight given.

  • 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-12T14:58:48+00:00Added an answer on June 12, 2026 at 2:58 pm

    probably the easiest way would be to delegate the permalink to the parent on the model

    CarImage < ActiveRecord:Base
      belongs_to :garage
      delegate : permalink, :to => :garage
      attr_accessible: :garage_id, :image
    
      mount_uploader :car_image, CarUploader
    
    
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is
Can someone please tell me how to delay the resetting of a div background-image
Can someone please assist me. I am trying to find a log on an
Can some one please assist me in this example of TabHost? The problem i
I hope someone can assist me please. I am using a pullout widget in
Can someone please point me to the easiest way to have a timer in
Can someone please point me to articles or books that discusses different programming paradigm
Can someone please derive a concrete example from the following: http://www.urdalen.com/blog/?p=210 ..that shows how
Can someone please explain what the & does in the following: class TEST {
Can someone please assist me on why my background color of the frame is

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.