Questions tagged [accepts-nested-attributes]

71 questions
1
vote
0 answers

nested attributes, update and create diferents tables and fields at the same time

In my application I have a goal, this goal belongs to a company and has start and end date, when it is created automatically values ​​are created in the day table that go between the start date and end date defined in the goal, this field has the…
1
vote
1 answer

nested attributes has many through

I have 3 models: class Day < ApplicationRecord belongs_to :goal has_many :day_salesmen, dependent: :destroy has_many :salesmen, through: :day_salesman validates_presence_of :date_day, :goal_id accepts_nested_attributes_for…
1
vote
1 answer

Accepts nested attributes safe params with jsonb and variable keys

I am attempting to allow parameters to go through my controller for a data attribute that is of type jsonb, the hash looks like so: data: { "en" => { "activities_text" => "Activities", "playlists_text" => "Playlists", …
rii
  • 1,578
  • 1
  • 17
  • 22
1
vote
1 answer

Rails 4 how to check if nested attributes _destroy flag is set from within model

I have model (container) that accepts nested attributes (including allow_destroy) for a has_one relationship to another model (reuse_request). There is a before_validation callback in the container model that I don't want to run if the the…
mahi-man
  • 4,326
  • 2
  • 25
  • 36
1
vote
0 answers

Not able to edit existing fields with accepts_nested_attributes_for

I have a @pitch that accepts_nested_attributes_for for features. I want to be able to edit and add features within the edit page of a @pitch (I'm using form_for). I've tried so many similar examples/tutorials and QA's and my code seems to be…
0
votes
2 answers

Rails Has Many Validate Unique Attribute With Accepts Nested Attributes For

I have Invoices with many Invoice Line Items. Invoice line items point to a specific item. When creating or updating an Invoice, I'd like to validate that there is not more than 1 invoice line item with the same Item (Item ID). I am using accepts…
karns
  • 5,391
  • 8
  • 35
  • 57
0
votes
1 answer

Rails simple form submits but nested fields from data doesn't persist

I'm working on a rails CMS project and I am trying to create from the admin dashboard, a quotes section where users can add a section_quote with title, image and five quotes with their authors(5 inputs for quotes and 5 for authors). The issue I have…
0
votes
1 answer

Rails Nested Fields With Cocoon - link_to_add_association is Deleting Records

I'm using nested fields and accept nested attributes with a 3 level nested relationship. The 3rd level (I don't think it matters that it's third level) relationship gets deleted when editing the parent. Setup has one material, material has one…
karns
  • 5,391
  • 8
  • 35
  • 57
0
votes
0 answers

Rails nested attributes method delete not working correctly

I have two models: Article and Paragraph. One Article can include much Paragraphs. Article model: class Article < ApplicationRecord #enum category: {wiki: "Wiki", rules: "Rules", blog: "Blog", draft: "Draft"} enum category: [:wiki, :rules,…
0
votes
1 answer

Rails + Javascript: Create one parent model and multiple child model in same time

I have a parent model (paper) and a nested child model (tape) and want to create multiple child with a parent in same time without using any gems. The input fields of tape should be dynamically added through clicking “+”. If I write “3.times {…
0
votes
0 answers

How to avoid saving nil/blank in accepts_nested_attributes_for when displaying set number of fields for has_many association?

My question is an edgecase of how to avoid saving empty records on a nested rails form. I have a simple has_many, where a user can have a maximum of 5 job titles. # user.rb has_many :job_titles validates_length_of :job_titles, maximum:…
stevec
  • 41,291
  • 27
  • 223
  • 311
0
votes
1 answer

Many to Many Relationship in Ruby on Rails, unable to created multiple records using Multiple Select Field

I have a many to many relationship between the two models (Region & Listing). I'm trying to use fields_for on the Listing form in order to multi-select Region's and have a Regionalization row created for each selected Region. I can achieve the…
Bradley
  • 922
  • 2
  • 8
  • 24
0
votes
0 answers

Ruby on Rails passing an empty hash for nested class creates entities with null values

When using accepts_nested_attributes_for in my project, if any of my nested attributes' hash has a nil value then I get an error saying, NoMethodError: undefined method 'with_indifferent_access' for nil:NilClass`. If I replace that nil value with…
Burak Kaymakci
  • 662
  • 2
  • 16
  • 36
0
votes
2 answers

How to create a Child before associating it to its Parent in rails?

I have Categories (Parents) within which are listed Products (Children). I want to be able to create a new Product directly from the navbar, anywhere in the app and then, during the creation, assign it to a Category. However, I get the present…
0
votes
2 answers

Rails _destroy field appearing twice in form

I have two models, Preset and Plot, as below: class Preset < ApplicationRecord belongs_to :user has_many :plots, :dependent => :destroy accepts_nested_attributes_for :plots, allow_destroy: true end class Plot < ApplicationRecord …