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

  • Home
  • SEARCH
  • 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 8300143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:26:10+00:00 2026-06-08T16:26:10+00:00

I have this (these) model(s) Portfolio — PortfolioItem item — Image image has_attachment :attachment

  • 0

I have this (these) model(s)

Portfolio
-- PortfolioItem item
  -- Image image
     has_attachment :attachment

all with nice slugs and I would want the url of :attachment to reflect this organization, such as with a instance

photos/holiday_in_venice/ponte_vecchio (all slugs of the respective hierarchy)

would generate this url

photos(??)/holiday_in_venice(??)/:slug/:style.:extension

how would I access these antecessor objects during paperclip path/url creation?

currently I am only able to do

ponte_vecchio/small.png
  • 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-08T16:26:11+00:00Added an answer on June 8, 2026 at 4:26 pm

    You’ll need to create custom interpolations. After that you are able define a :url and a :path.

    Put a file called paperclip.rb in your config/initializers/ folder and do something like this:

    Paperclip.interpolates :portfolio_slug do |attachment, style|
      attachment.instance.portfolio_item.portfolio.title.parameterize
    end
    
    Paperclip.interpolates :portfolio_slug do |attachment, style|
      attachment.instance.portfolio_item.title.parameterize
    end
    

    After that you can use those interpolations like that:

    has_attached_file :attachment, 
      :path=>":rails_root/public/photos/:portfolio_slug/:item_slug/:style.:extension",
      :url=>"/photos/:portfolio_slug/:item_slug/:style.:extension"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this simplified Model: https://i.stack.imgur.com/d2WsV.png I have these Elements ordered in an NSOutlineView
I have this code in my model when the controller requests to get all
I have already have this code to force these URLs to HTTPS: RewriteCond %{HTTPS}
I have this code which will include template.php file from inside each of these
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
I have urls like this: www.wunderwedding.com/weddingvenues/share-weddingvenue/175/beachclub-all-good www.wunderwedding.com/weddingvenues/share-weddingvenue/2567/castle-rock Since these urls no longer exist, I
I have these 3 tables: and I'm using this code to join them together
I have these variables: boost::regex re //regular expression to use std::string stringToChange //replace this
I have these (sample) lines in a HTML-file: test.ABC.test test.ABCD.test test.ABCE.test And this Ant
Alright this is my first day with JQuery so have fun with these functions

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.