Questions tagged [accepts-nested-attributes]
71 questions
0
votes
1 answer
Mass assign a collection of existing records rails
I am trying to assign a collection of existing records to an existing (or new) associated record.
For example:
class List < ApplicationRecord
has_and_belongs_to_many :items, join_table: :list_items
accepts_nested_attributes_for…

benjamin ratelade
- 263
- 2
- 3
0
votes
0 answers
Rails carrierwave-base64 with accepts_nested_attributes_for
I'm trying to use carrierwave-base64 and accepts_nested_attributes_for to upload files but I get "File can't be blank" error. Here's an example of what I'm trying:
post.rb
has_many :post_files, dependent: :destroy
accepts_nested_attributes_for…

Daniel Ishitani
- 53
- 6
0
votes
1 answer
Rails 5: Nested attributes aren't updated for model
I can't get rails to update my nested attributes, though regular attributes work fine. This is my structure:
unit.rb:
class Unit < ApplicationRecord
has_many :unit_skill_lists
has_many :skill_lists, through: :unit_skill_lists, inverse_of:…

schoel
- 793
- 1
- 6
- 14
0
votes
1 answer
How to resolve a NoMethodError on a controller dealing with multiple models?
I have a single form that submits two models, Participant and StudentDetail.
Participant has_one Student_Detail, whose attributes are nested within Participant. When trying to access the form, I am getting a NoMethodError stating that…

dbate
- 127
- 13
0
votes
0 answers
Rails nested form with has_many :through
I have 3 models, the product model has a connection to the firm model through the product_categories model. I want to create a form where I can add product with their category, within the firm form.
Firm model
class Firm < ApplicationRecord
…

Damjan Radev
- 56
- 2
0
votes
0 answers
Unpermitted parameters: offices in a has_many :through association in Rails 5
I have a has_many through association. When I go to the Store form I need to save Owner data in the same form. But I keep getting Unpermitted parameters: :offices. I tried with inverse_of as well. I tried changing the models structures like trying…

Michael Russell
- 11
- 4
0
votes
1 answer
Nested attributes with acceptance radio buttons
I have next models:
class Student < ApplicationRecord
has_many :special_offers_participants
end
class SpecialOffersParticipant < ApplicationRecord
belongs_to :special_offer
belongs_to :student
end
class SpecialOffer <…

Oleg Boris
- 3
- 1
0
votes
0 answers
Rails accepts_nested_attributes_for and a ternary association
tl, dr: Is it possible to populate a ternary association with accepts_nested_attributes and consequently pass the tests from this PR?
Basically I created four models A, B, C and Abc and the latter is a join table for a ternary association with the…

waldyr.ar
- 14,424
- 6
- 33
- 64
0
votes
1 answer
UPDATED: Rails form with nested_fields and multiple has_one
I have the following models:
class Property < ApplicationRecord
# Other validations
has_one :address
accepts_nested_attributes_for :address, update_only: true
end
class Address < ApplicationRecord
has_one :country
has_one :state
…

Isaac Gonzalez
- 1,734
- 1
- 16
- 22
0
votes
1 answer
Nested attributes with has one association in Ruby on Rails
Today I was trying to write a nested form with House and Address.
# app/models/house.rb
class House < ApplicationRecord
has_one :address
accepts_nested_attributes_for :address
end
# app/models/address.rb
class Address < ApplicationRecord
…

Berkhan Berkdemir
- 499
- 5
- 19
0
votes
1 answer
Why am I getting this unpermitted params error?
I have a PortStock model that looks like this:
class PortStock < ApplicationRecord
has_many :closed_positions, dependent: :destroy
accepts_nested_attributes_for :closed_positions, allow_destroy: true
end
My ClosedPosition model look like…

marcamillion
- 32,933
- 55
- 189
- 380
0
votes
1 answer
Rails Nested Attributes JSON Formatting
I'm trying to override the 'as_json' method to include nested attributes for an object, but I'm having trouble properly nesting the JSON.
Currently, I have this in Rails for my 'as_json' method.
// User.rb
def as_json(options = {})
json = {:id =>…

Travis Smith
- 622
- 5
- 22
0
votes
1 answer
How to delete child during update with reject_if option for accepts_nested_attributes_for
I am on Rails 5.0. I'm not quite sure if this should work or if I need to take a different approach. I have models for Procedure and Complication where Procedure has_many Complications defined like so;
class Procedure < ActiveRecord::Base
has_many…

brad
- 9,573
- 12
- 62
- 89
0
votes
0 answers
ActiveRecord::RecordNotFound: Couldn't find ModelName with ID= when using accepts_nested_attributes_for
For example, I have three model classes:
class Promotion < ApplicationRecord
has_many :promotion_sets, dependent: :destroy
accepts_nested_attributes_for :promotion_sets
end
class PromotionSet < ApplicationRecord
belongs_to :promotion
…

Trần Kim Dự
- 5,872
- 12
- 55
- 107
0
votes
1 answer
Rails 5 with Devise - Devise User has_one Login
I am making a website for an existing database. This database is from a game and I can't make many changes in the existing tables.
I decided to use Devise as the authentication solution.
I will use the User model from Devise for the website and…

Breno Nogueira
- 53
- 9