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 `safe_constantize' #70

Open
jess opened this issue Jun 7, 2017 · 1 comment
Open

NoMethodError: undefined method `safe_constantize' #70

jess opened this issue Jun 7, 2017 · 1 comment

Comments

@jess
Copy link

jess commented Jun 7, 2017

Was getting this error. Traced it to the search engine model.

For some reason my enable_for configs are coming through as classes and not strings as is expected by the search_engine model and safe_constantize is not defined on Active::Record classes. I had to comment out for it to work.

jess@1c277b9

This is what my search config looks like:

Refinery::Search.configure do |config|
  config.enable_for = ["Refinery::Page", "Refinery::Projects::Property", "Refinery::Blog::Post"]
  # config.page_url = "/search"
  config.results_per_page = 50
end

Any idea how an array of strings could be converted to an array of classes? I check code and can't find anything in the search gem that would suggest conversion.

[4] pry(Refinery::Search::SearchEngine)> Refinery::Search.config.enable_for
=> [Refinery::Page(id: integer, parent_id: integer, path: string, slug: string, custom_slug: string, show_in_menu: boolean, link_url: string, menu_match: string, deletable: boolean,draft: boolean, skip_to_first_child: boolean, lft: integer, rgt: integer, depth: integer, view_template: string, layout_template: string, created_at: datetime, updated_at: datetime),
 Refinery::Projects::Property(id: integer, title: string, photo_id: integer, body: text, side_bar: text, position: integer, created_at: datetime, updated_at: datetime, published: boolean, featured: boolean, architect: string, owner_developer: string, general_contractor: string, address: string, city: string, state: string, county: string, completion_date: string, structure_type: string, services_provided: string, related_links: string, photo_credit: string, latitude: decimal, longitude: decimal, in_the_works: boolean, zip: string, projectid: string)]

I tried creating another array in the config and it comes out just fine:

Refinery::Search.configure do |config|
...
  config.enable_for_model = ["Refinery::Page", "Refinery::Projects::Property", "Refinery::Blog::Post"]
...
end
[2] pry(Refinery::Search::SearchEngine)> Refinery::Search.config.enable_for_model.first
=> "Refinery::Page"

Must not be an issue for anyone else, but thought I'd throw it out and see if anyone has suggestions.

@markquezada
Copy link

I was seeing this too when I upgraded from refinery 2 to 3. My issue was that when I initially ported over the class names from the version 2 format, I wrote them like this:

Refinery::Search.configure do |config|
  config.enable_for = [Refinery::Page, Refinery::Calendar::Event]
end

Because in v2, it is an array of classes, but in v3 they need to be strings:

Refinery::Search.configure do |config|
  config.enable_for = ['Refinery::Page', 'Refinery::Calendar::Event']
end

I was seeing this issue even after I made the change, too, because I forgot to restart my server after fixing it.

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