Questions tagged [accepts-nested-attributes]

71 questions
6
votes
1 answer

How to add many to many record which having extra column

I have following Models User has_many :users_contacts has_many :contacts, through: :users_contacts accepts_nested_attributes_for :contacts, allow_destroy: true Contact has_many :users_contacts has_many :users, through:…
Salil
  • 46,566
  • 21
  • 122
  • 156
3
votes
1 answer

Unable to UPDATE nested attributes even when providing record ID

I am trying to update nested records, but for some reason it does not work and my update action is ignored. If I run the following code in console, it returns true, but nothing is actually updated for field_values_attributes, only steps_attributes…
Miroslav
  • 158
  • 2
  • 22
3
votes
1 answer

Id field using "accepts_nested_attributes_for" disappears when using datatables in Rails

Background: I am using simple_form to render nested attributes of an association in rails. I have applied jquery-datatables gem on the edit form for the nested association using simple_fields_for. My model is: has_many :foos, dependent:…
3
votes
3 answers

Do not raise ActiveRecord::RecordNotFound if nested attributes marked for destruction do not exist

I'm using Rails nested attributes with allow_destroy: true. If I call something like this: deck.update(deck_items_attributes: { id: 1000, _destroy: true }) and the deck_item with id 1000 does not exist Rails raise the exception…
Pioz
  • 6,051
  • 4
  • 48
  • 67
2
votes
0 answers

Ruby on Rail Nested Attributes do not save to database

I am trying to create a form that updates 2 tables - commission_type and commission_tier. I created the models, controller and form but when I submit it, my commission_tier table does not update. Only my commission_type table updates. Can someone…
David Lee
  • 571
  • 6
  • 20
2
votes
0 answers

I got duplicate validation errors when use accepts_nested_attributes_for in both models. Could I avoid this?

I have the following models: class User < ApplicationRecord belongs_to :company accepts_nested_attributes_for :company end class Company < ApplicationRecord has_one :user accepts_nested_attributes_for :user, update_only: true validates…
2
votes
1 answer

Rails not saving image through accepts_nested_attributes_for

I am trying to save an image through ActiveStorage using a accepts_nested_attributes. It works fine when I edit the child record, but when I place it in the form it looks like everything works, but it isn't actual saving. Bellow is my code that I…
2
votes
0 answers

Customized hash for nested attributes errors in rails

I have addresses & phones associations against the user model which means that a user can have multiple addresses and multiple phones. I have to store 1 address and 1 phone at the time of signup where I am using devise_token_auth…
2
votes
0 answers

rails - assign preexisting record as nested association while updating nested attributes

I am not using a rails form as this is all coming from an XML that I am parsing. For my requirement, I need to assign an existing record as nested association while at the same time, updating selected attributes of that association. My models are…
Martin Verdejo
  • 1,229
  • 2
  • 13
  • 24
2
votes
0 answers

How to allow record save event if the nested association validation fails

I have a case where a model Parent has many children. The model Child has some validations. In the Parent model form, I'm building multiple instances of the model Child using nested attributes. The problem is that if one of the children's…
Ruur
  • 185
  • 10
2
votes
1 answer

Can I delete missing associations using accepts_nested_attributes_for in rails?

TL;DR This seems like it should be really simple. I want to set up #accepts_nested_attributes_for such that when I save the parent class with any non-empty params set for the the child class, it deletes any other children that aren't directly…
Arepo
  • 825
  • 1
  • 9
  • 23
2
votes
1 answer

how can we get only newly added object after update using accepts_nested_attributes_for assocation in rails

My association looks like this : class Abc < ApplicationRecord has_many :def accepts_nested_attributes_for :def, allow_destroy: true end class AbcController < ApplicationController def update abc = Abc.find(params[:id]) if…
2
votes
1 answer

Rails Accepts Nested Attributes Uniqueness Validations

I've got a simple form that allows managing the positions at a company. I'm using the accepts_nested_attributes API to achieve this. Users are able to add / remove positions using plus / minus buttons and select the user and position for each. The…
Stussa
  • 3,375
  • 3
  • 24
  • 35
2
votes
1 answer

Rails update_attributes for a specific associated model

I have the following setup: class Post < ApplicationRecord has_many :comments, inverse_of: :post, dependent: :destroy accepts_nested_attributes_for :comments end class Comment < ApplicationRecord belongs_to :post end If I call…
1
vote
1 answer

nested attributes with has many through

I am getting unpermitted params when I am passing values from UI. The association is many to many between models. class User < ApplicationRecord has_many :user_posts has_many :posts, through: :user_posts end class Post < ApplicationRecord …
1
2 3 4 5