Module: Wallaby::Urlable

Included in:
ApplicationConcern, ApplicationHelper
Defined in:
lib/concerns/wallaby/urlable.rb

Overview

All URL helpers for Engine

Instance Method Summary collapse

Instance Method Details

#edit_path(resource, url_params: {}) ⇒ String

Generate the resourceful edit path for given resource.

Parameters:

  • resource (Object)
  • url_params (Hash) (defaults to: {})

Returns:

  • (String)

    edit page path



60
61
62
63
64
65
66
67
# File 'lib/concerns/wallaby/urlable.rb', line 60

def edit_path(resource, url_params: {})
  decorated = decorate resource
  with_query = url_params.delete :with_query
  url_for(
    { action: :edit, id: decorated.primary_key_value }.merge(url_params),
    { model_class: decorated.model_class, with_query: with_query }
  )
end

#index_path(model_class, url_params: {}) ⇒ String

Generate the resourceful index path for given model class.

Parameters:

  • model_class (Class)
  • url_params (Hash) (defaults to: {})

Returns:

  • (String)

    index page path



23
24
25
26
27
28
29
# File 'lib/concerns/wallaby/urlable.rb', line 23

def index_path(model_class, url_params: {})
  with_query = url_params.delete :with_query
  url_for(
    { action: :index }.merge(url_params),
    { model_class: model_class, with_query: with_query }
  )
end

#new_path(model_class, url_params: {}) ⇒ String

Generate the resourceful new path for given model class.

Parameters:

  • model_class (Class)
  • url_params (Hash) (defaults to: {})

Returns:

  • (String)

    new page path



35
36
37
38
39
40
41
# File 'lib/concerns/wallaby/urlable.rb', line 35

def new_path(model_class, url_params: {})
  with_query = url_params.delete :with_query
  url_for(
    { action: :new }.merge(url_params),
    { model_class: model_class, with_query: with_query }
  )
end

#show_path(resource, url_params: {}) ⇒ String

Generate the resourceful show path for given resource.

Parameters:

  • resource (Object)
  • url_params (Hash) (defaults to: {})

Returns:

  • (String)

    show page path



47
48
49
50
51
52
53
54
# File 'lib/concerns/wallaby/urlable.rb', line 47

def show_path(resource, url_params: {})
  decorated = decorate resource
  with_query = url_params.delete :with_query
  url_for(
    ParamsUtils.presence(action: :show, id: decorated.try(:primary_key_value)).merge(url_params),
    { model_class: decorated.model_class, with_query: with_query }
  )
end

#url_for(params = nil, options = {}) ⇒ String

Override original method to handle URL generation **when Wallaby is mounted as Rails Engine**.

Parameters:

  • params (String, Hash, ActionController::Parameters, nil) (defaults to: nil)
  • options (Hash) (defaults to: {})

    options only used by EngineUrlFor

Returns:

  • (String)

    URL string

See Also:



13
14
15
16
17
# File 'lib/concerns/wallaby/urlable.rb', line 13

def url_for(params = nil, options = {})
  (!options[:super] &&
    EngineUrlFor.execute(context: self, params: params, options: options)) ||
    super(params)
end