Module: Wallaby::LinksHelper
- Included in:
- BaseHelper
- Defined in:
- lib/helpers/wallaby/links_helper.rb
Overview
Links helper
Instance Method Summary collapse
-
#cancel_link(html_options = {}, &block) ⇒ String
Return link to cancel an action.
-
#delete_link(resource, html_options: {}, &block) ⇒ String?
Return link to delete action by a given model class If user’s not authorized, nil will be returned.
-
#edit_link(resource, options: {}, html_options: {}, &block) ⇒ String
Return link to edit page by a given model class If user’s not authorized, resource label will be returned.
-
#edit_path(resource) ⇒ String
Url for edit form page of given resource.
-
#index_link(model_class, url_params: {}, html_options: {}, &block) ⇒ String?
Return link to index page by a given model class If user’s not authorized, nil will be returned.
-
#index_params ⇒ Object
Permit the params used by Wallaby.
-
#index_path(model_class, url_params: {}) ⇒ String
Url for index page.
-
#new_link(model_class, html_options: {}, &block) ⇒ String?
Return link to create page by a given model class If user’s not authorized, nil will be returned.
-
#new_path(model_class) ⇒ String
Url for new resource form page.
-
#show_link(resource, options: {}, html_options: {}, &block) ⇒ String
Return link to show page by a given model class If user’s not authorized, resource label will be returned.
-
#show_path(resource) ⇒ String
Url for show page of given resource.
Instance Method Details
#cancel_link(html_options = {}, &block) ⇒ String
Return link to cancel an action
107 108 109 110 |
# File 'lib/helpers/wallaby/links_helper.rb', line 107 def cancel_link( = {}, &block) block ||= -> { t 'links.cancel' } link_to :back, , &block end |
#delete_link(resource, html_options: {}, &block) ⇒ String?
Return link to delete action by a given model class If user’s not authorized, nil will be returned
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/helpers/wallaby/links_helper.rb', line 88 def delete_link(resource, html_options: {}, &block) return if cannot? :destroy, extract(resource) , block = LinkOptionsNormalizer.normalize( , block, class: 'resource__destroy', block: -> { t 'links.delete' } ) [:method] ||= :delete [:data] ||= {} [:data][:confirm] ||= t 'links.confirm.delete' link_to show_path(resource), , &block end |
#edit_link(resource, options: {}, html_options: {}, &block) ⇒ String
Return link to edit page by a given model class If user’s not authorized, resource label will be returned
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/helpers/wallaby/links_helper.rb', line 69 def edit_link(resource, options: {}, html_options: {}, &block) default = [:readonly] && decorate(resource).to_label || nil return default if cannot? :edit, extract(resource) , block = LinkOptionsNormalizer.normalize( , block, class: 'resource__update', block: -> { "#{t 'links.edit'} #{decorate(resource).to_label}" } ) link_to edit_path(resource), , &block end |
#edit_path(resource) ⇒ String
Url for edit form page of given resource
145 146 147 148 149 150 |
# File 'lib/helpers/wallaby/links_helper.rb', line 145 def edit_path(resource) decorated = decorate resource return unless decorated.primary_key_value wallaby_engine.edit_resource_path \ decorated.resources_name, decorated.primary_key_value end |
#index_link(model_class, url_params: {}, html_options: {}, &block) ⇒ String?
Return link to index page by a given model class If user’s not authorized, nil will be returned
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/helpers/wallaby/links_helper.rb', line 15 def index_link(model_class, url_params: {}, html_options: {}, &block) return if cannot? :index, model_class , block = LinkOptionsNormalizer.normalize( , block, block: -> { to_model_label model_class } ) path = index_path model_class, url_params: url_params link_to path, , &block end |
#index_params ⇒ Object
Permit the params used by Wallaby
5 6 7 |
# File 'lib/helpers/wallaby/links_helper.rb', line 5 def index_params params.except(:resources, :utf8).permit(:filter, :page, :per, :q, :sort) end |
#index_path(model_class, url_params: {}) ⇒ String
Url for index page
116 117 118 119 120 121 122 123 |
# File 'lib/helpers/wallaby/links_helper.rb', line 116 def index_path(model_class, url_params: {}) if url_params.is_a?(::ActionController::Parameters) \ && !url_params.permitted? url_params = {} end wallaby_engine.resources_path \ to_resources_name(model_class), url_params.to_h end |
#new_link(model_class, html_options: {}, &block) ⇒ String?
Return link to create page by a given model class If user’s not authorized, nil will be returned
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/helpers/wallaby/links_helper.rb', line 32 def new_link(model_class, html_options: {}, &block) return if cannot? :new, model_class , block = LinkOptionsNormalizer.normalize( , block, class: 'resource__create', block: -> { t 'links.new', model: to_model_label(model_class) } ) link_to new_path(model_class), , &block end |
#new_path(model_class) ⇒ String
Url for new resource form page
128 129 130 |
# File 'lib/helpers/wallaby/links_helper.rb', line 128 def new_path(model_class) wallaby_engine.new_resource_path to_resources_name(model_class) end |
#show_link(resource, options: {}, html_options: {}, &block) ⇒ String
Return link to show page by a given model class If user’s not authorized, resource label will be returned
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/helpers/wallaby/links_helper.rb', line 49 def show_link(resource, options: {}, html_options: {}, &block) # NOTE: to_s is a must # if a block is returning integer (e.g. `{ 1 }`) # `link_to` will render blank text note inside hyper link , block = LinkOptionsNormalizer.normalize( , block, block: -> { decorate(resource).to_label.to_s } ) default = [:readonly] && block.call || nil return default if cannot? :show, extract(resource) link_to show_path(resource), , &block end |
#show_path(resource) ⇒ String
Url for show page of given resource
135 136 137 138 139 140 |
# File 'lib/helpers/wallaby/links_helper.rb', line 135 def show_path(resource) decorated = decorate resource return unless decorated.primary_key_value wallaby_engine.resource_path \ decorated.resources_name, decorated.primary_key_value end |