Questions tagged [accepts-nested-attributes]
71 questions
1
vote
2 answers
Is there a suggested way to create nested many-to-many entities in RoR that avoids *_attributes in the JSON field for the nested resource?
I've managed to get nested many-to-many entities created through the use of accepts_nested_attributes_for for the JSON and the project below.
My question is - is there a suggested way to achieve the same thing where I don't have to add _attributes…

foamroll
- 752
- 7
- 23
1
vote
1 answer
Recursive accepts_nested_attributes_for in Rails, is it possible?
I want to create a tree structure between two models, Bar and Foo.
Bar has many Foos
Bar
/ | \
Foo Foo Foo
¦
Bar
/ | \
Foo Foo Foo
Bar can optionally belong to Foo.
Bar has many Foos, to infinity and beyond...
I…

Jonathan
- 10,936
- 8
- 64
- 79
1
vote
0 answers
Rails 6 Nested Attributes, Uniquness Validation Failing on destroyed records
I am facing issue in validating nested attributes uniquness. I have 2 models
#model : CompanyStore
class CompanyStore < ApplicationRecord
has_many :company_stores_brands, dependent: :destroy
accepts_nested_attributes_for…

Ankita Agrawal
- 422
- 5
- 20
1
vote
2 answers
How to use nested forms in Rails if the fields have the same name?
I have two models, Dog and Owner, and I want their names to be the same, and would be redundant if I asked to fill out the fields twice (once for the dog and another time for the owner). I'm wondering if there's a simpler way to update the two…

Lee Sung Hye
- 47
- 3
1
vote
1 answer
Devise strong_params on Nested attributes form
I am following this tutorial [https://kakimotonline.com/2014/03/30/extending-devise-registrations-controller/][1], whose purpose is creating a Devise User, and its owning Company on the same form.
Models :
class User < ActiveRecord::Base
devise…

pierrecode
- 192
- 2
- 15
1
vote
2 answers
Nested attributes in rails 5.0 errored while saving the record
I have User model (for devise ) and then i have member which references User and then portfolio which references member .
i have created a user while signingup .
Now i want the signed up user to update his deatails which is members and portfolio…

user2742176
- 11
- 2
1
vote
1 answer
Rails accepts_nested_attributes_for not working with has_many relationship and cocoon gem
I'm using the cocoon gem to build a form that creates a Tournament. A Tournament has_many Games. Cocoon lets me dynamically add more games to the form.
When I call @tournament.save, it generates the following errors:
Games team one must exist
Games…

Adam Zerner
- 17,797
- 15
- 90
- 156
1
vote
1 answer
Access childrens using where condition for nested attributes
I have the following relationship set, dashboard filter values have a column called filter_type which can have value 1 or 0.
class DashboardFilterValue < ApplicationRecord
belongs_to :dashboard_filter
end
class DashboardFilter <…

opensource-developer
- 2,826
- 4
- 38
- 88
1
vote
1 answer
Rails 6: Can't delete nested model. Random Insert statement
I using Rails 6 with Postgres and having issues deleting a nested model.
A random insert statement gets generated after the association has been deleted.
Let me explain my set up.
Migrations
class CreateEntries < ActiveRecord::Migration[6.0]
def…

user346443
- 4,672
- 15
- 57
- 80
1
vote
1 answer
Forms for has_one but not always
I have two models: Personand User. A person can have a single user or no user at all, but every user have to be belong to a person.
I have set both models like so:
Person (has a has_user attribute):
has_one :user, dependent:…

Giovanni Di Toro
- 797
- 1
- 14
- 34
1
vote
1 answer
How do I prevent multiple simple_fields_for forms showing up?
I have a simple_fields_for form that is rendered within an iterator, like so:
<%= simple_form_for @port_stock, url: port_stocks_sell_order_path, method: :post, html: { class: "form-inline" } do |f| %>
<% @buy_port_stocks.each do |port_stock| %>
…

marcamillion
- 32,933
- 55
- 189
- 380
1
vote
3 answers
Rails nested attributes and changing associations
This one has had me stumped all day!
I have the following models:
Pump class
class Pump < ApplicationRecord
has_one :control, as: :equipment
accepts_nested_attributes_for :control
Pump Schema
class CreatePumps < ActiveRecord::Migration[5.1]
…

Mr Citizen
- 37
- 1
- 5
1
vote
2 answers
Accept Nested Attributes with class_name
Having trouble with accepting nested attributes when I've changed the class name. I'm sure I am just missing something obvious but just can't seem to find it.
models/walk.rb
class Walk < ApplicationRecord
has_many :attendees, class_name:…

Tyler Rowsell
- 125
- 6
1
vote
0 answers
Destroying accepts_nested_attributes_for association via unchecked checkboxes
I'm creating checkboxes in a form that represent the notification methods a user is subscribed to, and that allow a user to subscribe to additional notification methods or unsubscribe from existing ones. Here's what the relationships look…

krasten
- 21
- 1
1
vote
1 answer
Use nested attributes for model without auto-incrementing ID
I have the following models with their corresponding schema definitions:
class Cube < ApplicationRecord
has_many :faces, inverse_of: :cube, dependent: :destroy
accepts_nested_attributes_for :faces
end
create_table "cubes", id: :uuid, default:…

Daniel Olivares
- 544
- 4
- 13