Class: Superform::Rails::Form
Overview
A Phlex::HTML view module that accepts a model and sets a ‘Superform::Namespace` with the `Object#model_name` as the key and maps the object to form fields and namespaces.
The ‘Form::Field` is a class that’s meant to be extended so you can customize the ‘Form` inputs to your applications needs. Defaults for the `input`, `button`, `label`, and `textarea` tags are provided.
The ‘Form` component also handles Rails authenticity tokens via the `authenticity_toklen_field` method and the HTTP verb via the `_method_field`.
Direct Known Subclasses
Defined Under Namespace
Classes: Field
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
- #around_template ⇒ Object
- #form_tag ⇒ Object
-
#initialize(model, action: nil, method: nil, **attributes) ⇒ Form
constructor
A new instance of Form.
- #key ⇒ Object
- #submit(value = submit_value, **attributes) ⇒ Object
- #view_template(&block) ⇒ Object
Constructor Details
#initialize(model, action: nil, method: nil, **attributes) ⇒ Form
Returns a new instance of Form.
77 78 79 80 81 82 83 |
# File 'lib/superform/rails.rb', line 77 def initialize(model, action: nil, method: nil, **attributes) @model = model @action = action @method = method @attributes = attributes @namespace = Namespace.root(key, object: model, field_class: self.class::Field) end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
17 18 19 |
# File 'lib/superform/rails.rb', line 17 def model @model end |
Instance Method Details
#around_template ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/superform/rails.rb', line 85 def around_template(&) form_tag do authenticity_token_field _method_field super end end |
#form_tag ⇒ Object
93 94 95 |
# File 'lib/superform/rails.rb', line 93 def form_tag(&) form action: form_action, method: form_method, **@attributes, & end |
#key ⇒ Object
109 110 111 |
# File 'lib/superform/rails.rb', line 109 def key @model.model_name.param_key end |
#submit(value = submit_value, **attributes) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/superform/rails.rb', line 101 def submit(value = submit_value, **attributes) input **attributes.merge( name: "commit", type: "submit", value: value ) end |
#view_template(&block) ⇒ Object
97 98 99 |
# File 'lib/superform/rails.rb', line 97 def view_template(&block) yield_content(&block) end |