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

  • SEARCH
  • Home
  • 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 3991354
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:36:20+00:00 2026-05-20T06:36:20+00:00

From the rails documentation: Nested attributes allow you to save attributes on associated records

  • 0

From the rails documentation: “Nested attributes allow you to save attributes on associated records through the parent.”

I am able to save attributes on associated records through the CHILD. (Which is great… but WHY is this not documented or explained?)

(This project can be cloned from github at: https://github.com/blasto333/Vehicles-Demo/)

Vehicle Model (Parent)

class Vehicle < ActiveRecord::Base
  has_one :car
  attr_accessible :name, :color, :price, :condition
end

# == Schema Information
#
# Table name: vehicles
#
#  id         :integer         not null, primary key
#  name       :string(255)
#  color      :string(255)
#  price      :string(255)
#  condition  :string(255)
#  created_at :datetime
#  updated_at :datetime
#

Car Model (Child)

class Car < ActiveRecord::Base
  belongs_to :vehicle
  accepts_nested_attributes_for :vehicle
  attr_accessible :doors, :sport, :vehicle_attributes
end


# == Schema Information
#
# Table name: cars
#
#  id         :integer         not null, primary key
#  vehicle_id :integer
#  doors      :integer
#  sport      :boolean
#  created_at :datetime
#  updated_at :datetime
#

Cars Controller

class CarsController < ApplicationController
  def new
    @car = Car.new
    @car.build_vehicle
  end

  def create
    Car.create(params[:car])
  end

end

Cars “new” view

<h1>Cars#new</h1>
<%= form_for @car do |car_form| %>
    <%= car_form.fields_for :vehicle do |vehicle_fields| %>
        <%=vehicle_fields.label :name%>: <%=vehicle_fields.text_field :name%><br />
        <%=vehicle_fields.label :color%>: <%=vehicle_fields.text_field :color%><br />
        <%=vehicle_fields.label :price%>: <%=vehicle_fields.text_field :price%><br />
        <%=vehicle_fields.label :condition%>: <%=vehicle_fields.text_field :condition%><br />
    <% end %>
    <%=car_form.label :doors%>: <%=car_form.text_field :doors%><br />
    <%=car_form.label :sport%>: <%=car_form.text_field :sport%><br />
    <%=car_form.submit%>
<% end %>
  • 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-20T06:36:21+00:00Added an answer on May 20, 2026 at 6:36 am

    http://apidock.com/rails/ActiveRecord/NestedAttributes/ClassMethods/accepts_nested_attributes_for

    Defines an attributes writer for the specified association(s). 
    

    It means all associations: has_many, has_one, belongs_to, habtm. So… everything looks pretty documented.

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

Sidebar

Related Questions

I'd like to be able to invoke a file download from rails using link
How might you call a Lisp program from a Rails application?... For example, allow
I have a engine style Rails plugin from which I can create a gem
I need to be able to render some views as PDFs from a Rails
The documentation from rails generate controller says: [--helper] # Indicates when to generate helper
I'm coming from a Rails background and doing some work on a ASP.NET project
I need to produce somewhat complicated PDFs from a Rails app - tables with
So I need to access this service from my rails app. I'm using soap4r
I'm trying to setup a simple timer that gets started from a Rails Application.
In PHP, I'm trying to steal a page from the Rails playbook (see 'Using

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.