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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:53:40+00:00 2026-05-25T00:53:40+00:00

assuming I have a Model A and a Model B. class A < ActiveRecord::Base

  • 0

assuming I have a Model A and a Model B.

class A < ActiveRecord::Base
  has_one :b
end

class B < ActiveRecord::Base
end

And a form for A where all possible B’s are listed for choosing.

...
<div class="field">
<%= f.label :hv_type_id %><br />
<%= f.collection_select :b_id, @bs, :id, :name %>
</div>
...

I did

@bs = B.all

in the controller method of A.


Is this best practice? What if A holds another assosiaction for e.g: C

Should the the controller of A load all C’s as well?

What is your expierience, do thinks like this slow down the application a lot?

Is there a way to handle this efficiently?

See http://en.wikibooks.org/wiki/Ruby_on_Rails/ActionView/Forms#Using_select_boxes_with_a_model

  • 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-25T00:53:40+00:00Added an answer on May 25, 2026 at 12:53 am

    Although your code as written will not work (e.g. you have two “Class A”, you use @bs in your controller but bs in your view – which are different variables, etc.), I get your drift. The answer is based on the number of records that you are retrieving for the select box.

    If it’s just a few, then there is no problem. If you are displaying hundreds or thousands of choices, that is definitely a problem, on multiple levels: it will create a huge page for the user to download, eating up a ton of bandwidth; and it will make their job of trying to find and select a record very difficult.

    If you have to associate with many records in this way, you would be better off using an auto-complete. Or, build the application so you start by choosing a sub-record before going to the form. E.g. step one would be to retrieve a “B” by using, say, a search, and step 2 would be adding additional information that is associated with B.

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

Sidebar

Related Questions

I have my models setup like so: class User < ActiveRecord::Base has_many :posts, :foreign_key
I have the following two classes: class Menu < ActiveRecord::Base has_many :menu_headers accepts_nested_attributes_for :menu_headers
Assuming I have a comments model and a posts model, What code can I
Assuming I have only the class name of a generic as a string in
Assuming I have a class A as follows: class A{ int id; int getId(){};
Assuming that I have such model COLORS= ( ('R', 'Red'), ('B', 'Yellow'), ('G', 'White'),
I have the following model: public class Blog { public int BlogID { get;
I have a database model class that is a NSObject . I have a
I have a model like this class Ask(models.Model): name = models.CharField(max_length=500) designation = models.CharField(max_length=200,
I have the following model: class Artist(models.Model): cell_phone = models.CharField(20) pr_phone = modelsCharField(20) In

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.