projectblacklight / spotlight

Spotlight enables librarians, curators, and others who are responsible for digital collections to create attractive, feature-rich websites that highlight these collections.
Other
161 stars 65 forks source link

Blacklight helper behaviors overridden by app not available to Spotlight engine #1154

Open rwd opened 9 years ago

rwd commented 9 years ago

Blacklight's strategy for allowing helpers to be overriden by an app, by using behavior modules, does not work with Spotlight.

For example, given a helper in the app containing:

module UrlHelper
  include Blacklight::UrlHelperBehavior

  def url_for_document(doc, options = {})
    '/special/path'
  end
end

Blacklight will use the app's overriden helper method, but Spotlight will not.

I expect that this is due to the Rails engine having isolated namespace and so being unaware of overrides in the app.

cbeer commented 9 years ago

I think we got around that for some other helpers by whitelisting the relevant application helpers:

   def main_app_url_helper?(method)
      (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) &&
        main_app.respond_to?(method)
    end

https://github.com/sul-dlss/spotlight/blob/master/app/helpers/spotlight/application_helper.rb#L156-159

I wonder if we should add that to the particular route to the whitelist, and hope there aren't too many similar ones (or, build out some engine configuration so application's can push the relevant overrides to Spotlight)?

Another couple workarounds I can think of are::

@jcoyne @jkeck @mejackreed ?

[1] https://github.com/projectblacklight/blacklight/blob/master/app/helpers/blacklight/url_helper_behavior.rb#L13-18

rwd commented 9 years ago

I don't think that the whitelist in Spotlight::ApplicationHelper#main_app_url_helper? will help here because the method is not missing; it is provided by Blacklight and so #main_app_url_helper? never gets called for it.