For Ruby on Rails 5.2.1
class User < ActiveRecord::Base belongs_to :organization accepts_nested_attributes_for :organization end class Organization < ActiveRecord::Base has_many :users end
Just got to your controller, suppose this is "users_controller.rb":
Class UsersController < ApplicationController def new @user = User.new @user.build_organization end end
And the view is the same as Nick did:
= form_for @user do |f| f.label :name, "Name" f.input :name = f.fields_for :organization do |o| o.label :city, "City" o.input :city f.submit "Submit"
In the end, we see that @ user3551164 has already been decided, but now (Ruby on Rails 5.2.1) we do not need attr_accessible :organization_attributes
FΓ‘bio AraΓΊjo Aug 22 '18 at 13:53 on 2018-08-22 13:53
source share