Skip to content

Commit

Permalink
Only use helper_method when the view layer is present
Browse files Browse the repository at this point in the history
In API mode, the view layer is not available and these trigger
method_missing errors. This fix is similar to how devise solved this
problem: heartcombo/devise#3732
  • Loading branch information
jcoyne authored and cbeer committed Dec 17, 2018
1 parent 62a0799 commit b9266bd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Metrics/MethodLength:
# Offense count: 9
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 208
Max: 211
Exclude:
- 'lib/blacklight/solr/search_builder_behavior.rb'

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module Blacklight::Catalog
# The following code is executed when someone includes blacklight::catalog in their
# own controller.
included do
helper_method :sms_mappings, :has_search_parameters?
if respond_to? :helper_method
helper_method :sms_mappings, :has_search_parameters?
end

helper Blacklight::Facet

Expand Down
15 changes: 9 additions & 6 deletions app/controllers/concerns/blacklight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ module Blacklight::Controller

# now in application.rb file under config.filter_parameters
# filter_parameter_logging :password, :password_confirmation
helper_method :current_user_session, :current_user, :current_or_guest_user
after_action :discard_flash_if_xhr

# handle basic authorization exception with #access_denied
rescue_from Blacklight::Exceptions::AccessDenied, :with => :access_denied

# extra head content
helper_method :has_user_authentication_provider?
helper_method :blacklight_config, :blacklight_configuration_context
helper_method :search_action_url, :search_action_path, :search_facet_url, :search_facet_path
helper_method :search_state
if respond_to? :helper_method
helper_method :current_user_session, :current_user, :current_or_guest_user

# extra head content
helper_method :has_user_authentication_provider?
helper_method :blacklight_config, :blacklight_configuration_context
helper_method :search_action_url, :search_action_path, :search_facet_path
helper_method :search_state
end

# Specify which class to use for the search state. You can subclass SearchState if you
# want to override any of the methods (e.g. SearchState#url_for_document)
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/concerns/blacklight/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
module Blacklight::SearchContext
extend ActiveSupport::Concern

# The following code is executed when someone includes blacklight::catalog::search_session in their
# The following code is executed when someone includes Blacklight::Catalog::SearchSession in their
# own controller.
included do
helper_method :current_search_session, :search_session
included do
if respond_to? :helper_method
helper_method :current_search_session, :search_session
end
end

module ClassMethods
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/concerns/blacklight/token_based_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module Blacklight::TokenBasedUser
extend ActiveSupport::Concern

included do
helper_method :encrypt_user_id
if respond_to? :helper_method
helper_method :encrypt_user_id
end

rescue_from Blacklight::Exceptions::ExpiredSessionToken do
head :unauthorized
Expand Down

0 comments on commit b9266bd

Please sign in to comment.