Module: DomFor::Model
- Included in:
- DomFor
- Defined in:
- lib/dom_for/model.rb
Overview
Name of classes Pages: index - users new - user new_user edit - user edit_user show - user show_user
ID name Pages: index - users new - new_user edit - user_1 show - user_1
Data-attributes Pages: index - data-action = index new - data-action = new edit - data-action = edit, data-object-id = 1 show - data-action = show, data-object-id = 1
Instance Method Summary collapse
-
#dom_for_model(klass, attrs = {}, &block) ⇒ String
Creates a div tag with the attributes for the model of ActiveRecord.
Instance Method Details
#dom_for_model(klass, attrs = {}, &block) ⇒ String
Creates a div tag with the attributes for the model of ActiveRecord
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dom_for/model.rb', line 54 def dom_for_model(klass, attrs={}, &block) object_classes = [] class_name = klass.to_s.underscore request_action = request.path_parameters[:action] attrs.merge!(action: request_action) if request_action.present? object = instance_variable_get("@#{class_name}") object_id = if object if object.persisted? attrs = attrs.merge(object_id: object.id, object: class_name.pluralize) end object_classes << dom_class(klass) object_classes << dom_class(klass, request_action) if request_action.present? dom_id(object) else object_classes << class_name.pluralize class_name.pluralize end if block_given? content_tag(:div, id: object_id, class: object_classes.join(' '), data: attrs, &block) else tag(:div, id: object_id, class: object_classes.join(' '), data: attrs) end rescue content_tag(:div, &block) end |