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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:53:33+00:00 2026-06-11T07:53:33+00:00

I have two models which are linked in a has_one / belongs_to association; Computer

  • 0

I have two models which are linked in a has_one / belongs_to association; Computer and Ipv6Address respectively.

I have pre-populated the Ipv6 table with all the entries that I want it to have, and I now need to have a drop-down list on the Computer new/edit forms to select an item from Ipv6 to associate it with.

Everything I’ve seen so far on this only seems to work when you are creating both objects at the same time on the new form and then subsequently editing them.

I’ve tried to set up my MVC’s as per the examples I’ve found online, but I keep getting errors, as underneath these code excerpts:

Computer model:

class Computer < ActiveRecord::Base
  accepts_nested_attributes_for :ipv6_address
  has_one :ipv6_address
  ...

Ipv6Address model:

class Ipv6Address < ActiveRecord::Base
  attr_accessible :computer_id, :ip_address
  belongs_to :computer
  ...

Computer controller:

class ComputersController < ApplicationController
  def new
    @computer = Computer.new
    @ipv6s = Ipv6Address.where('computer_id IS NULL').limit(5)
  end

  def edit
    @computer = Computer.find(params[:id])
    @ipv6s = Ipv6Address.where('computer_id = #{@computer.id} OR computer_id IS NULL').order('computer_id DESC').limit(5)
  end

Computer new form:

<%= simple_form_for( @computer ) do |f| %>
  <%= f.fields_for :ipv6_addresses do |v6| %>
    <%= v6.input :ipv6_address, :collection => @ipv6s %>
  <% end %>
  <% f.button :submit %>
<% end %>

Error when browsing to computer new form:

NoMethodError in ComputersController#new

private method `key?' called for nil:NilClass

No line of code reference is given for this error, but it only appears when I have the nested form included in the computer new form.

Any ideas as to what is causing it or how I can better go about what I’m doing?

EDIT:

As it turns out, I needed to have accepts_nested_attributes_for :ipv6_address after the line has_one :ipv6_address in the Computer model.

That fixed the issue with the form loading.

As per Yarden’s answer, I then also singularized all instances of “ipv6_address” so as to reflect the has_one relationship.

Once doing that in the new form, however, the ipv6 field completely disappeared. I’ll open a new question with this one if I can’t get it sorted out shortly.

  • 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-11T07:53:35+00:00Added an answer on June 11, 2026 at 7:53 am

    Try adding ‘:’, I think that may be the problem :

     <%= f.fields_for :ipv6_addresses do |v6| %>
    

    Also you forgot to add a ‘.’ here:

    @ipv6s = Ipv6Address.where('computer_id IS NULL').limit(5)
    

    Edit after change:

    The problem is that its only a has_one relationship so it doesnt know the plural of :ipv6_address as you stated in your model… you need to change it to :ipv6_address instead of :ipv6_addresses…

    Also in your form change the :ipv6_address to the actual field which is :ip_address.

    So overall your form should look like this:

    <%= simple_form_for( @computer ) do |f| %>
    <%= f.fields_for :ipv6_address do |v6| %>
    <%= v6.input :ip_address, :collection => @ipv6s %>
    <% end %>
    <% f.button :submit %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models which are linked in a has_one / belongs_to association; Computer
I have two models which are related to each other: /** @Entity @Table(name=permissions) */
I have two models, TreeNode and User. Each user has_one TreeNode, which is the
I have two models: Person and Address which I'd like to create in a
I have two models User and Category that have a HABTM association. I would
I have two models (say A and B) which are independent and have independent
I have two models, Project and Category, which have a many-to-many relationship between them.
As the title suggests I have two models Products And Orders which are actually
I have two models in Django linked together by ManyToMany relation like this: class
The problem is I have two models - Project and Ticket (which belongs to

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.