Bartosz Michalak


50 Experience
0 Lessons Completed
0 Questions Solved


Posted in accepts_nested_attributes_for and :reject_if

Hello everybody!
I have problem with nested attributes:.

My model:

class MainTransactionElement < ApplicationRecord
    has_one :external_source
    accepts_nested_attributes_for :external_source, :reject_if => :is_external_source_blank?

    def is_external_source_blank?
        is_external_source_checkbox == '0'

During the first load of form, it works. But is one bug:

  1. Checkbox is unchecked and form won't pass the validation and render again.
  2. In next render form doesn't generate nested attributes and I check checkbox.
  3. In next render, nested attributes still doesn't generate, despite the previously marked checkbox.

Any ideas why?