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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:02:55+00:00 2026-05-23T23:02:55+00:00

I currently have a form set up with nested models – all going according

  • 0

I currently have a form set up with nested models – all going according to plan so far. The form allows me to create a sale, and from that I can create a customer and a vehicle (separate models).

The problem comes when I try to create a registration number, which is a separate model nested from vehicle; essentially I can get a text box to appear on the form, but trying to create a registration number results in a can not mass assign protected attribute :registration_number error in the console, and when editing a sale that includes a vehicle with a registration number, the text box is empty.

The models involved are:

class Sale < ActiveRecord::Base
  attr_accessible :customer_id, :vehicle_id, :sale_date, 
                  :customer_attributes, :vehicle_attributes

  belongs_to :customer
  accepts_nested_attributes_for :customer

  belongs_to :vehicle
  accepts_nested_attributes_for :vehicle

end

and

class Vehicle < ActiveRecord::Base
  attr_accessible :first_registration_date, :hidden, :registration_numbers_attributes

  has_many :sales
  has_many :customers, :through => :sales

  has_many :vehicle_registration_numbers, :dependent => :delete_all
  has_many :registration_numbers, :through => :vehicle_registration_numbers
  accepts_nested_attributes_for :registration_numbers, :allow_destroy => true

end

and

class RegistrationNumber < ActiveRecord::Base

  attr_accessible :number

  has_many :vehicle_registration_numbers, :dependent => :delete_all
  has_many :vehicles, :through => :vehicle_registration_numbers

end

and

class VehicleRegistrationNumber < ActiveRecord::Base

  belongs_to :vehicle
  belongs_to :registration_number

end

The form in question is:

<%= form_for @sale, :html => {:class => 'fullform'} do |f| %>

<%= field_set_tag 'Customer Details' do %>
    <%= f.fields_for :customer do |builder| %>
        <snip>
    <% end %>
<% end %>

<%= field_set_tag 'Vehicle Details' do %>
    <%= f.fields_for :vehicle do |vehicle_builder| %>
        <snip>
            <%= f.fields_for :registration_numbers do |registration_number_builder| %>
                <%= registration_number_builder.text_field :number, :class => 'formtxtbox-short' %>
            <% end %>
    <% end %>
<% end %>

<% end %>

Any assistance would be greatly appreciated – thanks!

  • 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-23T23:02:55+00:00Added an answer on May 23, 2026 at 11:02 pm

    You mis-nested your resources, see arrow below.

    <%= field_set_tag 'Vehicle Details' do %>
      <%= f.fields_for :vehicle do |vehicle_builder| %>
        <snip>
     ===>> <%= vehicle_builder.fields_for :registration_numbers do |registration_number_builder| %>
                <%= registration_number_builder.text_field :number, :class => 'formtxtbox-short' %>
            <% end %>
      <% end %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I create a nested list, I currently have this public function getNav($cat,$subcat){
I currently have a Form with all the desired effects except one. The current
We don't currently have our SQL Server objects in any form of source control.
I have a search form in an app I'm currently developing, and I would
I currently have speakers set up both in my office and in my living
I currently have a Form with a TabControl containing some TabPage s. Each TabPage
I have a dropdown list that is currently populated from a result set of
I have a nested Form A Crew can have many meetings, a Meeting can
I have a nested custom control that I need to set focus on. I
I have Teacher, Student, and Parent models that all belong to User. This is

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.