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

Rails4.2 compatibility when use colon(::) for class name. #9

Closed
kntmrkm opened this issue Dec 21, 2014 · 3 comments
Closed

Rails4.2 compatibility when use colon(::) for class name. #9

kntmrkm opened this issue Dec 21, 2014 · 3 comments

Comments

@kntmrkm
Copy link

kntmrkm commented Dec 21, 2014

I have posted question #4.
Today, upgrade to rails 4.2.

I'm using

  • ruby 2.1.3
  • search_cop 1.0.3

so, An error occurred like below.

NameError - uninitialized constant Setting:
  activesupport (4.2.0) lib/active_support/dependencies.rb:533:in `load_missing_constant'
  activesupport (4.2.0) lib/active_support/dependencies.rb:184:in `const_missing'
  activesupport (4.2.0) lib/active_support/inflector/methods.rb:261:in `block in constantize'
  activesupport (4.2.0) lib/active_support/inflector/methods.rb:259:in `constantize'
  activesupport (4.2.0) lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
  search_cop (1.0.3) lib/search_cop_grammar/attributes.rb:70:in `klass_for'
  search_cop (1.0.3) lib/search_cop_grammar/attributes.rb:81:in `attribute_for'
  search_cop (1.0.3) lib/search_cop_grammar/attributes.rb:55:in `block in attributes'
  search_cop (1.0.3) lib/search_cop_grammar/attributes.rb:55:in `attributes'
  search_cop (1.0.3) lib/search_cop_grammar/attributes.rb:47:in `compatible?'
  search_cop (1.0.3) lib/search_cop_grammar.rb:87:in `block in evaluate'
  search_cop (1.0.3) lib/search_cop_grammar.rb:87:in `evaluate'
  search_cop (1.0.3) lib/search_cop_grammar.rb:14:in `evaluate'
  search_cop (1.0.3) lib/search_cop/grammar_parser.rb:18:in `parse'
  search_cop (1.0.3) lib/search_cop.rb:25:in `parse'
  search_cop (1.0.3) lib/search_cop/query_builder.rb:10:in `initialize'
  search_cop (1.0.3) lib/search_cop.rb:61:in `unsafe_search_cop'
  search_cop (1.0.3) lib/search_cop.rb:53:in `search_cop'
  search_cop (1.0.3) lib/search_cop.rb:44:in `block in search_scope'

My model code is

  include SearchCop
  search_scope :searching do
    attributes :name, :name_kana, :domain_name, :address
    attributes setting: ['account_settings.catch_copy', 'account_settings.formal_name']
    aliases account_settings: :setting
  end

  has_one :setting, dependent: :destroy

And I changed aliases to aliases account_settings: Account::Setting.
But error is NameError - uninitialized constant AccountSetting:.

@mrkamel
Copy link
Owner

mrkamel commented Dec 21, 2014

Hi, thanks for reporting. That's a rails 4.2. regression:

Account.reflections[:setting] # works in < 4.1, but not 4.2
Account.reflections["setting"] # works in 4.2, but not < 4.1

Thus, we now have to check both. I created a branch https://github.com/mrkamel/search_cop/tree/rails_42_reflection_fix to fix this. Could you check if it's working for you

gem "search_cop", :git => "https://github.com/mrkamel/search_cop.git", :branch => "rails_42_reflection_fix"

@kntmrkm
Copy link
Author

kntmrkm commented Dec 22, 2014

Thanks for branch.

It works! Thanks.

aliases account_settings: 'setting'

@mrkamel
Copy link
Owner

mrkamel commented Dec 22, 2014

v1.0.4 is out to fix this issue

@mrkamel mrkamel closed this as completed Dec 22, 2014
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

No branches or pull requests

2 participants