Class: Locomotive::Liquid::Tags::ModelForm
- Inherits:
-
Solid::Block
- Object
- Solid::Block
- Locomotive::Liquid::Tags::ModelForm
- Defined in:
- lib/locomotive/liquid/tags/model_form.rb
Overview
Display the form html tag with the appropriate hidden fields in order to create a content entry from a public site. It handles callbacks, csrf and target url out of the box.
Usage:
model_form ‘newsletter_addresses’ %
<input type='text' name='content[email]' />
<input type='submit' value='Add' />
endform_form %
model_form ‘newsletter_addresses’, class: ‘a-css-class’, success: ‘www.google.fr’, error: ‘/error’ %…endform_form %
Instance Method Summary collapse
- #callbacks_html(options) ⇒ Object
- #content_type_html(name) ⇒ Object
- #csrf_html ⇒ Object
- #display(*options, &block) ⇒ Object
Instance Method Details
#callbacks_html(options) ⇒ Object
44 45 46 47 48 |
# File 'lib/locomotive/liquid/tags/model_form.rb', line 44 def callbacks_html() .slice(:success, :error).map do |(name, value)| html_tag :input, type: 'hidden', name: "#{name}_callback", value: value end.join('') end |
#content_type_html(name) ⇒ Object
33 34 35 |
# File 'lib/locomotive/liquid/tags/model_form.rb', line 33 def content_type_html(name) html_tag :input, type: 'hidden', name: 'content_type_slug', value: name end |
#csrf_html ⇒ Object
37 38 39 40 41 42 |
# File 'lib/locomotive/liquid/tags/model_form.rb', line 37 def csrf_html name = controller.send(:request_forgery_protection_token).to_s value = controller.send(:form_authenticity_token) html_tag :input, type: 'hidden', name: name, value: value end |
#display(*options, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/locomotive/liquid/tags/model_form.rb', line 22 def display(*, &block) name = .shift = .shift || {} form_attributes = { method: 'POST', enctype: 'multipart/form-data' }.merge(.slice(:id, :class)) html_content_tag :form, content_type_html(name) + csrf_html + callbacks_html() + yield, form_attributes end |