Skip to content

label for polymorphic association throws ArgumentError:"Polymorphic associations do not support computing the class" #1557

Open
@imme5150

Description

@imme5150

I'll try to write a test if you can't reproduce it, but this should be enough details to reproduce:

rails (6.1.7.10)
ransack (4.3.0)
ruby 3.1.7p261

form.haml:

1    = search_form_for [:admin, @search] do |f|
2       = f.label :source_of_Order_type_number_eq do
3           Order Number
4           = f.text_field :source_of_Order_type_number_eq

If I replace line 2 with:
= label_tag 'q[source_of_order_type_number_eq]'
There is no error, and the text_field tag actually works. Also if I run Payment.ransack with source_of_Order_type_number_eq it works and generates the correct SQL

Full stacktrace:
activerecord (6.1.7.10) lib/active_record/reflection.rb:407:in 'compute_class'
activerecord (6.1.7.10) lib/active_record/reflection.rb:366:in 'klass'
ransack (4.3.0) lib/ransack/adapters/active_record/context.rb:96:in 'klassify'
ransack (4.3.0) lib/ransack/context.rb:139:in 'association_path'
ransack (4.3.0) lib/ransack/translate.rb:77:in 'attribute_name'
ransack (4.3.0) lib/ransack/translate.rb:38:in 'block in attribute'
ransack (4.3.0) lib/ransack/translate.rb:37:in 'map'
ransack (4.3.0) lib/ransack/translate.rb:37:in 'attribute'
ransack (4.3.0) lib/ransack/nodes/grouping.rb:24:in 'translate'
ransack (4.3.0) lib/ransack/search.rb:19:in 'translate'
ransack (4.3.0) lib/ransack/helpers/form_builder.rb:35:in 'label'
app/views/payments/form.html.haml:2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions