refinery / refinerycms-search

Search Plugin for RefineryCMS
65 stars 59 forks source link

NoMethodError: undefined method `safe_constantize' #70

Open jess opened 7 years ago

jess commented 7 years ago

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.

https://github.com/jess/refinerycms-search/commit/1c277b9f9f0b8648e24b572d52b7f02c876df77e

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 commented 6 years ago

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.