class Object

Public Instance Methods

_back_to_anchor_url() click to toggle source
# File lib/back_to_anchor/url_helper.rb, line 16
def _back_to_anchor_url
  referrer = _filtered_referrer
  if referrer
    anchor_param = controller.request.query_parameters.dig(:to_anchor)
    anchor_param ? "#{referrer}##{anchor_param}" : referrer
  else
    "javascript:history.back()"
  end
end
url_for(options = nil) click to toggle source
Calls superclass method
# File lib/back_to_anchor/routing_url_for.rb, line 2
def url_for(options = nil)
  case options
  when String
    options
  when nil
    super(only_path: _generate_paths_by_default)
  when Hash
    options = options.symbolize_keys
    unless options.key?(:only_path)
      options[:only_path] = only_path?(options[:host])
    end

    super(options)
  when ActionController::Parameters
    unless options.key?(:only_path)
      options[:only_path] = only_path?(options[:host])
    end

    super(options)
  when :back
    _back_url
  when :back_to_anchor
    _back_to_anchor_url
  when Array
    components = options.dup
    if _generate_paths_by_default
      polymorphic_path(components, components.extract_options!)
    else
      polymorphic_url(components, components.extract_options!)
    end
  else
    method = _generate_paths_by_default ? :path : :url
    builder = ActionDispatch::Routing::PolymorphicRoutes::HelperMethodBuilder.send(method)

    case options
    when Symbol
      builder.handle_string_call(self, options)
    when Class
      builder.handle_class_call(self, options)
    else
      builder.handle_model_call(self, options)
    end
  end
end