Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `value' for #<Arel::SelectManager #1467

Open
spaghetticode opened this issue Dec 15, 2023 · 0 comments · May be fixed by #1468
Open

NoMethodError: undefined method `value' for #<Arel::SelectManager #1467

spaghetticode opened this issue Dec 15, 2023 · 0 comments · May be fixed by #1468

Comments

@spaghetticode
Copy link

I'm experiencing this issue starting from Ransack 3.2 which removes the support for Rails 6 and some ancillary code.

The issue is happening here and is caused by the fact that in my context the right predicate for a Arel::Nodes::In predicate is a Arel::SelectManager rather than a Arel::Nodes::Casted, so we can't call #value on it:

module Ransack
  module Nodes
    class Condition < Node
      # ...
      def casted_array?(predicate)
        predicate.value.is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
      end

The fix should be pretty simple: just check for the class before calling #value on the predicate.

For more context, the previous implementation didn't raise because there was an extra support method that hid the fact that the predicate may not respond to either #val or #value:

        def casted_array?(predicate)
          value_from(predicate).is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
        end

        def value_from(predicate)
          if predicate.respond_to?(:value)
            predicate.value # Rails 6.1
          elsif predicate.respond_to?(:val)
            predicate.val # Rails 6.0
          end
        end

So, in my case this was equivalent to nil.is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)

spaghetticode added a commit to peterberkenbosch/solidus that referenced this issue Dec 15, 2023
Issue: activerecord-hackery/ransack#1467
PR: activerecord-hackery/ransack#1468

Hopefully the PR will be merged soon so we can remove this patch.
elia pushed a commit to peterberkenbosch/solidus that referenced this issue Dec 20, 2023
Issue: activerecord-hackery/ransack#1467
PR: activerecord-hackery/ransack#1468

Hopefully the PR will be merged soon so we can remove this patch.
elia pushed a commit to peterberkenbosch/solidus that referenced this issue Dec 20, 2023
Issue: activerecord-hackery/ransack#1467
PR: activerecord-hackery/ransack#1468

Hopefully the PR will be merged soon so we can remove this patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant