app/controllers/saved_searches_controller.rb in blacklight-6.0.0.pre5 vs app/controllers/saved_searches_controller.rb in blacklight-6.0.0
- old
+ new
@@ -1,24 +1,30 @@
+# frozen_string_literal: true
class SavedSearchesController < ApplicationController
include Blacklight::Configurable
copy_blacklight_config_from(CatalogController)
before_action :require_user_authentication_provider
before_action :verify_user
-
+
def index
@searches = current_user.searches
end
-
- def save
+
+ def save
current_user.searches << searches_from_history.find(params[:id])
if current_user.save
flash[:notice] = I18n.t('blacklight.saved_searches.add.success')
else
flash[:error] = I18n.t('blacklight.saved_searches.add.failure')
end
- redirect_to :back
+ if respond_to? :redirect_back
+ redirect_back fallback_location: blacklight.saved_searches_path
+ else
+ # Deprecated in Rails 5.0
+ redirect_to :back
+ end
end
# Only dereferences the user rather than removing the item in case it
# is in the session[:history]
def forget
@@ -28,25 +34,30 @@
flash[:notice] =I18n.t('blacklight.saved_searches.remove.success')
else
flash[:error] = I18n.t('blacklight.saved_searches.remove.failure')
end
- redirect_to :back
+ if respond_to? :redirect_back
+ redirect_back fallback_location: blacklight.saved_searches_path
+ else
+ # Deprecated in Rails 5.0
+ redirect_to :back
+ end
end
-
+
# Only dereferences the user rather than removing the items in case they
# are in the session[:history]
- def clear
+ def clear
if current_user.searches.update_all("user_id = NULL")
flash[:notice] = I18n.t('blacklight.saved_searches.clear.success')
else
- flash[:error] = I18n.t('blacklight.saved_searches.clear.failure')
+ flash[:error] = I18n.t('blacklight.saved_searches.clear.failure')
end
redirect_to blacklight.saved_searches_url
end
-
protected
+
def verify_user
flash[:notice] = I18n.t('blacklight.saved_searches.need_login') and raise Blacklight::Exceptions::AccessDenied unless current_user
end
end