reform: Using the simple_form association form helper doesn't work?

If I try to use the association helper in a simple_form, I get an Association not found error, even if the underlying AR model has that association.

Example:

= simple_form_for @object do |f|
  = f.association :association_name

Looking at the simple_form code here they seem to check for the association by calling reflection_on_association on the class of the object underlying the form. And it seems that Reform::Form does not respond to this method, so the association helper fails.

Is there something else I should be doing/specifying in my Form object to make this work, or is it just not supported?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 29 (17 by maintainers)

Most upvoted comments

Here’s the updated form object and view:

class ClusterForm < Reform::Form
  include ModelReflections

  properties :name,
    validates: {
      presence: true
    }

  property :consent_agreement

  collection :sections, populate_if_empty: Section, prepopulator: ->(*) { self.sections = [Section.new] } do
    properties :class_number,
      :strm,
      :_destroy

    validates :class_number,
      presence: true

    validates :strm,
      presence: true
  end
end
        - cluster.prepopulate! unless cluster.errors.any?
        = f.simple_fields_for :sections do |sf|
          = sf.input :class_number, placeholder: 'The section\'s class #'
          = sf.input :strm, label: 'Term', collection: Term.present_or_future.undergrad