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

The Archive Base Latest Questions

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

I have these 2 models: class Person < ActiveRecord::Base attr_accessible :contact, :name validates :name,

  • 0

I have these 2 models:

class Person < ActiveRecord::Base
  attr_accessible :contact, :name

  validates :name, :presence => true

  has_many :books

end

class Register < ActiveRecord::Base
  attr_accessible :checkin, :checkout, :notes, :person, :book

end

In registers/_form.html.erb I want to use f.collection_select where I can select a Person’s name from a list. The purpose of the Register model is to record a history of checkouts.

This is my first time trying to use collection_select and I can’t wrap my head around it with the examples I have read on stackoverflow and google. Maybe I don’t have all that is needed in the models?

Please help.

  • 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-15T07:48:16+00:00Added an answer on June 15, 2026 at 7:48 am

    There are errors in your model with regards to associations. The correct associations should be:

    class Person < ActiveRecord::Base
       has_many :registers, :inverse_of => :person
    end
    
    class Register < ActiveRecord::Base
       belongs_to :person, :inverse_of => :registers
    end
    

    Then in your registers/_form.html.erb you have to have something like the following:

    <%= form_for :register do |f| %>
       <% # ... input elements for the rest of the Register model %>
    
       <%= f.collection_select :person_id, Person.all, :id, :name %>
    
       <% # ... input elements for the rest of the Register model %>
    
       <%= f.submit %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these models: class Gallery(models.Model): HeadImage = models.ImageField(upload_to=gallery,blank=True,null=True) class News(Gallery): Name=models.CharField(max_length=100) #some other
If I have a RoR model person.rb as follows: class Person < ActiveRecord::Base attr_accessible
I have the following: class Person < ActiveRecord::Base has_many :tasks end class Task <
I have these models: class Person(models.Model): name=models.CharField(max_length=100) family=models.CharField(max_length=100) class MailContact(models.Model): person=models.ForeignKey(Person) email=models.CharField(max_length=100) #some fields
Let's say I have these models: class A(models.Model): name = models.CharField(max_length=32) b = models.ForeignKey(B,
I have these simple classes Class A(models.Model): ... Class Meta(models.Model): a = models.OnetoOneField(A, primary_key=True)
I have these models: Person has_many :messages_form_person, :foreign_key => :from_user_id, :class_name => :messages has_many
I have the following two models class ContactField < ActiveRecord::Base end class Address <
Greetings, I have these 2 models: from django.db import models class Office(models.Model): name =
What I have now: class User < ActiveRecord::Base has_many :people end ... and... class

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.