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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:14:01+00:00 2026-06-15T03:14:01+00:00

I have a nested form which creates many locations for each post. Each location

  • 0

I have a nested form which creates many locations for each post. Each location can also be used in multiple posts.

E.g. Post 1 may have Location1, Location2 and Location3

AND Post 2 may have Location1, Location4 and Location5

I want these locations to be ordered within the posts in the same order that they were added. I assume the easiest way to do this is to add an ‘order’ column to the joining table (Posts_Locations) however i’m not sure how to set this up or define :order_by in my controller. Should I do this with directly with SQL?

Any suggestions? Is this the best way to do this?

  • 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-15T03:14:02+00:00Added an answer on June 15, 2026 at 3:14 am

    If you’re using a simple join table and the has_and_belongs_to_many for both Post and Location, you may want to make the posts_locations table a model in its own right, joining the two using has_many :through. This is well described here in this Rails guide.

    Bonus hint: when you’re adding the new column, change the model, and thus join table name to something singular, like PostLocation which will result in a table name post_locations … or perhaps something more descriptive. Also, don’t use the word “order” for this field, since it’s a keyword in both rails and SQL. Maybe call it “display_order”?

    Then in the PostLocation model you might create a scope, or even a default scope that defines the proper order., e.g. scope :sorted, order("display_order DESC")

    The other question I might ask: is it really the case that the order of the Posts is linked to whichever location and vice-versa?

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

Sidebar

Related Questions

I have a nested form Parent, which accepts attribute for Child. In my controller#new,
I have the following form for photo_album which uses the nested forms feature of
I have a nested json. I want to post it as a form input
I have a table of venues where each can have many offers. I have
I have comments nested inside posts which are nested in games. I cannot for
I have a nested form which is submitting through a create function in my
I am trying to make a nested model form in which I can add/delete
I have a nested form in my app that uses AJAX to load an
I have a complicated nested form (Ryan Bates' version) with .live() attached to some
I am running rails 3.2 I have created a nested form (requests > tags)

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.