Ask A Question


You’re not receiving notifications from this thread.

accepts_nested_attributes_for and :reject_if

Bartosz Michalak asked in Rails

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?

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.