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: {}) { ... } ⇒ String
Return link to cancel action.
-
#delete_link(resource, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to delete action for a given model class.
-
#edit_link(resource, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to edit page for a given model class.
-
#index_link(model_class, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to index page for a given model class.
-
#new_link(model_class, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to create page for a given model class.
-
#show_link(resource, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to show page for a given model class.
Instance Method Details
#cancel_link(html_options: {}) { ... } ⇒ String
Return link to cancel action
141 142 143 144 |
# File 'lib/helpers/wallaby/links_helper.rb', line 141 def cancel_link(html_options: {}, &block) block ||= -> { wt 'links.cancel' } link_to 'javascript:history.back()', , &block end |
#delete_link(resource, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to delete action for a given model class.
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/helpers/wallaby/links_helper.rb', line 121 def delete_link(resource, options: {}, url_params: {}, html_options: {}, &block) return if (:destroy, extract(resource)) || resource.try(:readonly?) , block = LinkOptionsNormalizer.normalize( , block, class: 'resource__destroy', block: -> { wt 'links.delete' } ) [:method] ||= :delete ([:data] ||= {})[:confirm] ||= wt 'links.confirm.delete' url = [:url] || show_path(resource.itself, url_params: url_params) link_to url, , &block end |
#edit_link(resource, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to edit page for a given model class.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/helpers/wallaby/links_helper.rb', line 95 def edit_link(resource, options: {}, url_params: {}, html_options: {}, &block) , block = LinkOptionsNormalizer.normalize( , block, class: 'resource__update', block: -> { "#{wt 'links.edit'} #{decorate(resource).to_label}" } ) default = ([:readonly] && block.call) || nil return default if (:edit, extract(resource)) || resource.try(:readonly?) url = [:url] || edit_path(resource.itself, url_params: url_params) link_to url, , &block end |
#index_link(model_class, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to index page for a given model class
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/helpers/wallaby/links_helper.rb', line 17 def index_link(model_class, options: {}, url_params: {}, html_options: {}, &block) return if (:index, model_class) , block = LinkOptionsNormalizer.normalize( , block, block: -> { to_model_label model_class } ) url = [:url] || index_path(model_class, url_params: url_params) link_to url, , &block end |
#new_link(model_class, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to create page for a given model class
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/helpers/wallaby/links_helper.rb', line 40 def new_link(model_class, options: {}, url_params: {}, html_options: {}, &block) return if (:new, model_class) || decorator_of(model_class).readonly? , block = LinkOptionsNormalizer.normalize( , block, class: 'resource__create', block: -> { wt 'links.new', model: to_model_label(model_class) } ) url = [:url] || new_path(model_class, url_params: url_params) link_to url, , &block end |
#show_link(resource, options: {}, url_params: {}, html_options: {}) { ... } ⇒ String?
Return link to show page for a given model class.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/helpers/wallaby/links_helper.rb', line 66 def show_link(resource, options: {}, url_params: {}, 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 (:show, extract(resource)) url = [:url] || show_path(resource.itself, url_params: url_params) link_to url, , &block end |