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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:08:00+00:00 2026-05-26T20:08:00+00:00

I am very new to rails development. I am creating a simple backend for

  • 0

I am very new to rails development.
I am creating a simple backend for my portfolio site.

I am not sure about the title of this question. A previous question I asked maybe too convoluted. So I am simplifying it.

Im using 3 models: Post, Attachment, Attachment_Category

I have a form that I use to:

  1. Draft the post with a title, content and a category.

  2. Display attachment categories in a drop down (slideshow, image, video)

  3. Upload the attachment(s).

I have implemented steps 1 and 2.

For step 3: I want it so that when I finally hit submit on the form, the attachment_category_id is saved to the attachment table.

I have the following relationships:

Post.rb

class Post < ActiveRecord::Base

has_many :attachment_categories, :through => :attachments
has_many :attachments,:dependent => :destroy

accepts_nested_attributes_for :attachments
validates_presence_of :title, :content, :category

end

Attachment.rb

class Attachment < ActiveRecord::Base

belongs_to :post
belongs_to :attachment_category


#paperclip
has_attached_file :photo, :styles =>{

:thumb => "100x100#",
:small => "400x400>"

}

end

Attachment_category.rb

class AttachmentCategory < ActiveRecord::Base

has_many :posts , :through => :attachments
has_many :attachments

validates :category_name, :presence =>true

end
  • 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-26T20:08:01+00:00Added an answer on May 26, 2026 at 8:08 pm

    So I have accomplished Steps 1, parts of step 2 and step 3.

    With my solution, I am able to upload just one attachment.
    But it works: The attachment gets saved to the Attachments table with the post_id and the attachment_category_id.

    The following code is from _form.html.erb which gets sent to post_controller.rb.
    Truncated code:

    .....
    
       <%= f.fields_for :attachments do |attach| %> <br>
    
       <%= attach.collection_select :attachment_category_id, AttachmentCategory.all, :id, :category_name %>
       <%= attach.file_field :photo %> <br>
    
       <% end %>
    
    .....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Warning - I am very new to NHibernate. I know this question seems simple
I am very new to Rails and Cucumber so this may or may not
Relatively new to rails and trying to model a very simple family tree with
I have built a very simple blog application using Ruby on Rails. New to
I'm very new with rails and I've been building a CMS application backend. All
I am very, very new to Rails development. I have read the arguments against
This is probably very straight forward and simple, but I'm very new and noob
I'm new to Rails development, so please bear with me. I'm creating a view
I am very new to Rails so this will probably seem basic to most
(Disclaimer: I am very new to rails) This plugin looks like it will be

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.