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

Already on GitHub? Sign in to your account

Can't use ransack on a field called "item_type" #159

Closed
fernandomm opened this Issue Nov 2, 2012 · 9 comments

Comments

Projects
None yet
7 participants

Hi,

I have a field called item_type on a model called Version. When i try to use this:

<%= f.text_field :item_type_cont, :class => "input-medium search-query" %>

It throws an exception:

uninitialized constant Version::Item

It works fine for other fields. Any ideas of why this happens?

Thanks.

Member

radar commented Nov 5, 2012

Which version of Ransack is this happening in?

Do you have a test Rails application that I can take a look at and
duplicate this problem?

On 3 November 2012 01:05, fernandomm notifications@github.com wrote:

Hi,

I have a field called item_type on a model called Version. When i try to
use this:

<%= f.text_field :item_type_cont, :class => "input-medium search-query" %>

It throws an exception:

uninitialized constant Version::Item

It works fine for other fields. Any ideas of why this happens?

Thanks.


Reply to this email directly or view it on GitHubhttps://github.com/ernie/ransack/issues/159.

I'm having the same issue with Rails 3.2.8, ruby 1.9.3 and Ransack 0.7.0. I'm trying to search id and type fields of a polymorphic model. For instance, the model is called DataError and has an errorable_id and errorable_type field. Attempting to search either of them gets a NameError: uninitialized constant DataError::Errorable

Member

radar commented Nov 13, 2012

Do you have a dummy application that reproduces this issue? This would aid
us greatly in tracking down what is causing this issue.

On 14 November 2012 02:44, Scott Carleton notifications@github.com wrote:

I'm having the same issue with Rails 3.2.8, ruby 1.9.3 and Ransack 0.7.0.
I'm trying to search id and type fields of a polymorphic model. For
instance, the model is called DataError and has an errorable_id and
errorable_type field. Attempting to search either of them gets a NameError:
uninitialized constant DataError::Errorable


Reply to this email directly or view it on GitHubhttps://github.com/ernie/ransack/issues/159#issuecomment-10330682.

Sure thing.

https://github.com/ScotterC/ransack_polymorphic_bug

Instructions included in the readme

Peleg commented May 24, 2013

I'm having the same issue... Any news on that?

ascoppa commented Jul 23, 2013

Same here 👎

Has anyone figured out a solution for this (or at least a workaround)?

Thanks

@sineed sineed pushed a commit to sineed/ransack that referenced this issue Nov 29, 2013

Denis Tataurov Add test to issue #159 bd2d555
Contributor

sineed commented Nov 29, 2013

I had the same issue and I found a WA: remove association from polymorphic model:

class Comment < ActiveRecord::Base
  # belongs_to :subject, polymorphic: true
end

It seems, that error occurs in view layer, I mean that

Comment.search(:subject_type_eq => "Article")

with uncommented belongs_to :subject works.

@radar, I wrote a test for this: #312

Contributor

sineed commented Nov 30, 2013

I figured out this strange behavior. For example, I have in my form:

<%= f.text_field :notable_type_cont %>

This line calls respond_to? method in Ransack::Search and passes "notable_type_cont_before_type_cast" as first argument. Then it calls attribute_method? in Ransack::Nodes::Grouping. In this method before processing it strips unnecessary info from string. So in case when I do

Note.search(notable_type_cont: "Article")

string "notable_type_cont" became "notable_type". In first form case it doesn't happen because of "_before_type_cast".

So I think when it calls attribute_method? in Ransack::Context the string should look like notable_type, not notable_type_cont_before_type_cast.

@radar I wrote a fix for that, but I'm not sure if I'm doing right thing. Can you see it? #313

@radar radar added a commit that referenced this issue Dec 4, 2013

@radar Denis Tataurov + radar Fix issue where trying to add a polymorphic field in search form resu…
…lted in NameError


Fixes #159
Fixes #313
37dbebc

@radar radar closed this in f491cb2 Dec 4, 2013

@sineed sineed pushed a commit to sineed/ransack that referenced this issue Dec 9, 2013

Denis Tataurov related with #159: remove from Ransack::search c33fbdd
Contributor

seanlinsley commented Dec 9, 2013

Looks like this was the same error I was experiencing over here: #173 (comment)

@jonatack jonatack added a commit that referenced this issue Dec 10, 2013

@jonatack jonatack Merge pull request #316 from sineed/fix_159_2
related with #159: remove `respond_to?` from Ransack::Search
9f0836d

@jonatack jonatack added a commit that referenced this issue Dec 10, 2013

@jonatack jonatack Catch up with commits on master from PR #316 and #317
PR #316 related with #159: remove `respond_to?` from Ransack::Search
PR #317 Allow specifying default attribute and predicate via
options[:default]
33297e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment