Module: ToolbarHelper
- Included in:
- ScavengerHunt::ApplicationHelper
- Defined in:
- app/helpers/toolbar_helper.rb
Instance Method Summary collapse
- #form_toolbar(form, options = {}) ⇒ Object
- #show_toolbar(instance, options = {}) ⇒ Object
- #submit_toolbar_item(form) ⇒ Object
- #toolbar(options = {}) ⇒ Object
- #toolbar_item(options = {}) ⇒ Object
Instance Method Details
#form_toolbar(form, options = {}) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/toolbar_helper.rb', line 2 def (form, = {}) = (, class: 'toolbar--footer') model_name = form.object.class.model_name.human.titleize navigate_back = do (form.object.persisted? ? link_to("View this #{model_name}", { action: :show }, class: 'button button--outline') : "".html_safe) + link_to("View all #{model_name.pluralize}", { action: :index }, class: 'button button--outline') end () do ( (form) + navigate_back + (block_given? ? yield : "") ).html_safe end end |
#show_toolbar(instance, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/toolbar_helper.rb', line 18 def (instance, = {}) delete_title = .delete(:delete_title) || "Delete" edit_or_delete = (tag: :div) do item = "".html_safe can_edit = .fetch(:edit) { policy(instance).edit? } item << link_to('Edit', { action: :edit }, class: 'button button--outline') if can_edit can_delete = .fetch(:delete) { policy(instance).destroy? } item << (delete_title, { action: :show }, title: "#{delete_title} #{instance}", class: 'button button--outline', data: { confirm: "Are you sure you want to #{delete_title.downcase} #{instance}?" }, method: :delete) if can_delete item end object_name = instance.class.model_name.human.titleize view_all = link_to("View all #{object_name.pluralize}", { action: :index }, class: 'button button--outline') = (, { class: 'toolbar--footer', tag: :nav, title: 'Actions' }) () do (edit_or_delete + view_all).html_safe end end |
#submit_toolbar_item(form) ⇒ Object
41 42 43 44 45 |
# File 'app/helpers/toolbar_helper.rb', line 41 def (form) do form.(:submit, class: 'toolbar-item') + link_to('Cancel', :back, class: 'button button--outline') end end |
#toolbar(options = {}) ⇒ Object
47 48 49 |
# File 'app/helpers/toolbar_helper.rb', line 47 def ( = {}) component(defaults: { class: 'toolbar' }, options: ) { yield if block_given? } end |
#toolbar_item(options = {}) ⇒ Object
51 52 53 |
# File 'app/helpers/toolbar_helper.rb', line 51 def ( = {}) component(defaults: { class: 'toolbar-item' }, options: , tag: :li) { yield if block_given? } end |