Module: NitroRails::InlineEditHelper
- Defined in:
- app/helpers/nitro_rails/inline_edit_helper.rb
Instance Method Summary collapse
- #attribute_classes(resource, attribute) ⇒ Object
- #editable_text(resource_path, attribute, context: :broadcast, placeholder: nil, focus: false, tag: :p) ⇒ Object
- #error_badge(resource, attribute) ⇒ Object
- #error_message(resource, attribute) ⇒ Object
- #togglable_checkbox(resource_path, attribute, context: :broadcast) ⇒ Object
- #updatable_text(resource, attribute, placeholder: nil) ⇒ Object
Instance Method Details
#attribute_classes(resource, attribute) ⇒ Object
44 45 46 |
# File 'app/helpers/nitro_rails/inline_edit_helper.rb', line 44 def attribute_classes(resource, attribute) "#{resource.class.name.downcase.dasherize}-#{attribute} #{resource.class.name.downcase.dasherize}-#{resource.id}-#{attribute} #{attribute}" end |
#editable_text(resource_path, attribute, context: :broadcast, placeholder: nil, focus: false, tag: :p) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/nitro_rails/inline_edit_helper.rb', line 3 def editable_text(resource_path, attribute, context: :broadcast, placeholder: nil, focus: false, tag: :p) render partial: 'nitro_rails/editable_text', locals: { resource_path: resource_path, resource: resource_path.is_a?(Array) ? resource_path.last : resource_path, attribute: attribute, context: context, placeholder: placeholder, focus: focus, tag: tag } end |
#error_badge(resource, attribute) ⇒ Object
30 31 32 33 34 35 |
# File 'app/helpers/nitro_rails/inline_edit_helper.rb', line 30 def error_badge(resource, attribute) error_count = resource.errors[attribute].length content_tag(:span, error_count, class: "error-badge #{'visible' if error_count > 0}", data: { attribute_error_count_id: resource.nitro_id(attribute) }) end |
#error_message(resource, attribute) ⇒ Object
37 38 39 40 41 42 |
# File 'app/helpers/nitro_rails/inline_edit_helper.rb', line 37 def (resource, attribute) = resource.errors.(attribute).first content_tag(:span, , class: "error-message #{'visible' if }", data: { attribute_error_message_id: resource.nitro_id(attribute) }) end |
#togglable_checkbox(resource_path, attribute, context: :broadcast) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/helpers/nitro_rails/inline_edit_helper.rb', line 15 def togglable_checkbox(resource_path, attribute, context: :broadcast) render partial: 'nitro_rails/togglable_checkbox', locals: { resource_path: resource_path, resource: resource = resource_path.is_a?(Array) ? resource_path.last : resource_path, attribute: attribute, context: context } end |
#updatable_text(resource, attribute, placeholder: nil) ⇒ Object
24 25 26 27 28 |
# File 'app/helpers/nitro_rails/inline_edit_helper.rb', line 24 def updatable_text(resource, attribute, placeholder: nil) content_tag(:span, resource.send(attribute).presence, class: "updatable-text", placeholder: placeholder, data: { nitro_id: resource.nitro_id(attribute) }) end |