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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:39:56+00:00 2026-05-23T19:39:56+00:00

I allow users to upload a photo. This photo is stored using paperclip. The

  • 0

I allow users to upload a photo. This photo is stored using paperclip. The model that I use to upload and store the photo is called Upload.

# Table name: uploads
#
#  id                 :integer         not null, primary key
#  created_at         :datetime
#  updated_at         :datetime
#  photo_file_name    :string(255)
#  photo_content_type :string(255)
#  photo_file_size    :integer
#  photo_updated_at   :datetime
#

have a model that I wish to link to the uploaded photo. It is called Message.

Table name messages
#  content            :string(255)
#  upload_id               :string(255)
#  created_at         :datetime
#  updated_at         :datetime

I want to use the upload_id to link the image to the message model.

However this means the association will be as follows

Message

belongs_to :upload


Upload

has_one :message

This seems a bit strange. To add more to the description I will also upload files for other models such as User. So I really would like to store the upload id in the table for each model that uses an upload.

Then how can I access the upload from an instance of a message

@message.upload_id.upload?
@user.upload_id.upload?

Thanks in advance

  • 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-23T19:39:57+00:00Added an answer on May 23, 2026 at 7:39 pm

    Correct your models classes:

    class Message < ActiveRecord::Base
      has_one :upload
    end
    
    class Upload < ActiveRecord::Base
      belongs_to :message
    end
    

    Create a migration to add a field message_id into uploads table.

    And then use @message.upload to access your upload model associated with the message.

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

Sidebar

Related Questions

I need to allow users to upload PDF documents that other users will read.
I'm using CKEditor and would like to be able to allow users to upload
I am using php and mysql. I allow my registered users to upload photos,
I'm using plupload to allow users to upload photos to my website, which works
I have an application that allows users to upload photos, which are stored in
So I am using the Uplodify plugin to allow users to upload multiple images
I'm working on a page that will allow a user to upload a photo
I want to allow users of an iPhone app to upload photos and use
I want to allow users of an iPhone app to upload photos and use
I need to allow my app's users to upload a photo to the app

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.