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…
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…
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…
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…
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…
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…
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 <…
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…
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:…
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| %> …
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] …
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:…
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…
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:…