module Wallaby::LinksHelper

Links helper

Public Instance Methods

default_path_params(resources: nil) click to toggle source

@return [Hash] default path params

# File lib/helpers/wallaby/links_helper.rb, line 206
def default_path_params(resources: nil)
  { script_name: request.env[SCRIPT_NAME] }.tap do |default|
    default[:resources] = resources if current_engine || resources
    default[:only_path] = true unless default.key?(:only_path)
  end
end
edit_path(resource, is_resource: false, url_params: {}) click to toggle source

@param resource [Object] @param is_resource [Boolean] @param url_params [Hash] @return [String] edit page path

# File lib/helpers/wallaby/links_helper.rb, line 192
def edit_path(resource, is_resource: false, url_params: {})
  decorated = decorate resource
  return unless is_resource || decorated.primary_key_value

  hash = ParamsUtils.presence(
    { action: :edit, id: decorated.primary_key_value },
    default_path_params(resources: decorated.resources_name),
    url_params.to_h
  )

  current_engine.try(:edit_resource_path, hash) || url_for(hash)
end
index_path(model_class, url_params: {}) click to toggle source

@param model_class [Class] @param url_params [Hash] @return [String] index page path

# File lib/helpers/wallaby/links_helper.rb, line 150
def index_path(model_class, url_params: {})
  hash = ParamsUtils.presence(
    { action: :index },
    default_path_params(resources: to_resources_name(model_class)),
    url_params.to_h
  )
  current_engine.try(:resources_path, hash) || url_for(hash)
end
new_path(model_class, url_params: {}) click to toggle source

@param model_class [Class] @param url_params [Hash] @return [String] new page path

# File lib/helpers/wallaby/links_helper.rb, line 162
def new_path(model_class, url_params: {})
  hash = ParamsUtils.presence(
    { action: :new },
    default_path_params(resources: to_resources_name(model_class)),
    url_params.to_h
  )
  current_engine.try(:new_resource_path, hash) || url_for(hash)
end
show_path(resource, is_resource: false, url_params: {}) click to toggle source

@param resource [Object] @param is_resource [Boolean] @param url_params [Hash] @return [String] show page path

# File lib/helpers/wallaby/links_helper.rb, line 175
def show_path(resource, is_resource: false, url_params: {})
  decorated = decorate resource
  return unless is_resource || decorated.primary_key_value

  hash = ParamsUtils.presence(
    { action: :show, id: decorated.primary_key_value },
    default_path_params(resources: decorated.resources_name),
    url_params.to_h
  )

  current_engine.try(:resource_path, hash) || url_for(hash)
end