Module: NitroRails::NitroActionHelper
- Defined in:
- app/helpers/nitro_rails/nitro_action_helper.rb
Instance Method Summary collapse
- #nitro_action_button(text, **options, &block) ⇒ Object
- #nitro_action_form(**options, &block) ⇒ Object
-
#nitro_create(type, **options, &block) ⇒ Object
CREATE ##.
- #nitro_create_button(text = nil, type, **options, &block) ⇒ Object
- #nitro_create_options(type, options) ⇒ Object
-
#nitro_destroy(resource = current_nitro_resource, **options, &block) ⇒ Object
DESTROY ##.
- #nitro_destroy_button(text_or_resource = nil, maybe_resource = current_nitro_resource, **options, &block) ⇒ Object
- #nitro_destroy_options(resource, options) ⇒ Object
- #nitro_hidden_action_form(**options, &block) ⇒ Object
-
#nitro_save(resource = current_nitro_resource, **options, &block) ⇒ Object
SAVE ##.
-
#nitro_save_button(text_or_resource = nil, maybe_resource = current_nitro_resource, **options, &block) ⇒ Object
No idea if any of the buttons are working.
- #nitro_save_options(resource, options) ⇒ Object
-
#nitro_update(resource = current_nitro_resource, **options, &block) ⇒ Object
UPDATE ##.
- #nitro_update_button(text_or_resource = nil, maybe_resource = current_nitro_resource, **options, &block) ⇒ Object
- #nitro_update_options(resource, options) ⇒ Object
Instance Method Details
#nitro_action_button(text, **options, &block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 9 def (text, **, &block) text ||= "Save" if !block_given? nitro_hidden_action_form(**) do |form| form.submit(text, &block) end end |
#nitro_action_form(**options, &block) ⇒ Object
3 4 5 6 7 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 3 def nitro_action_form(**, &block) nitro_hidden_action_form(**) do |form| form.submit_div(&block) end end |
#nitro_create(type, **options, &block) ⇒ Object
CREATE ##
28 29 30 31 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 28 def nitro_create(type, **, &block) (type, ) nitro_action_form(**, &block) end |
#nitro_create_button(text = nil, type, **options, &block) ⇒ Object
33 34 35 36 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 33 def (text=nil, type, **, &block) (type, ) (text, **, &block) end |
#nitro_create_options(type, options) ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 38 def (type, ) () do || .default(:method, :post) .default(:model, type.to_s.classify.constantize.new) .default(:params, type.to_sym => .delete(:params) || {}) end end |
#nitro_destroy(resource = current_nitro_resource, **options, &block) ⇒ Object
DESTROY ##
98 99 100 101 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 98 def nitro_destroy(resource = current_nitro_resource, **, &block) (resource, ) nitro_action_form(**, &block) end |
#nitro_destroy_button(text_or_resource = nil, maybe_resource = current_nitro_resource, **options, &block) ⇒ Object
103 104 105 106 107 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 103 def (text_or_resource = nil, maybe_resource = current_nitro_resource, **, &block) resource, text = (text_or_resource, maybe_resource) (resource, ) (text, **, &block) end |
#nitro_destroy_options(resource, options) ⇒ Object
109 110 111 112 113 114 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 109 def (resource, ) () do || .default(:method, :delete) .default(:model, resource) end end |
#nitro_hidden_action_form(**options, &block) ⇒ Object
17 18 19 20 21 22 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 17 def nitro_hidden_action_form(**, &block) nitro_form(**) do |form| concat(form.generate_hidden_attribute_fields) concat(yield(form)) end end |
#nitro_save(resource = current_nitro_resource, **options, &block) ⇒ Object
SAVE ##
50 51 52 53 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 50 def nitro_save(resource = current_nitro_resource, **, &block) (resource, ) nitro_action_form(**, &block) end |
#nitro_save_button(text_or_resource = nil, maybe_resource = current_nitro_resource, **options, &block) ⇒ Object
No idea if any of the buttons are working
56 57 58 59 60 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 56 def (text_or_resource = nil, maybe_resource = current_nitro_resource, **, &block) resource, text = (text_or_resource, maybe_resource) (resource, ) (text, **, &block) end |
#nitro_save_options(resource, options) ⇒ Object
63 64 65 66 67 68 69 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 63 def (resource, ) () do || .default(:method, resource.persisted? ? :patch : :post) .default(:model, resource) .default(:params, resource.type.to_sym => .delete(:params) || {}) end end |
#nitro_update(resource = current_nitro_resource, **options, &block) ⇒ Object
UPDATE ##
75 76 77 78 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 75 def nitro_update(resource = current_nitro_resource, **, &block) (resource, ) nitro_action_form(**, &block) end |
#nitro_update_button(text_or_resource = nil, maybe_resource = current_nitro_resource, **options, &block) ⇒ Object
80 81 82 83 84 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 80 def (text_or_resource = nil, maybe_resource = current_nitro_resource, **, &block) resource, text = (text_or_resource, maybe_resource) (resource, ) (text, **, &block) end |
#nitro_update_options(resource, options) ⇒ Object
86 87 88 89 90 91 92 |
# File 'app/helpers/nitro_rails/nitro_action_helper.rb', line 86 def (resource, ) () do || .default(:method, :patch) .default(:model, resource) .default(:params, resource.type.to_sym => .delete(:params) || {}) end end |