Method: Tolaria::FormBuildable#slug_field

Defined in:
lib/tolaria/form_buildable.rb

#slug_field(method, options = {}) ⇒ Object

Returns a text field that parameterizes its input as users type and renders it into the given preview template. Useful for demonstrating the value of a URL or other sluggified text.

Special Options

  • :pattern - Should be a string that includes an asterisk (*) character. As the user types, the asterisk will be replaced with a parameterized version of the text in the text box and shown in a preview area below the field. The default is "/blog-example/*".

Other options are forwarded to text_field.



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/tolaria/form_buildable.rb', line 116

def slug_field(method, options = {})
  pattern = options.delete(:pattern)
  preview_value = self.object.send(method).try(:parameterize).presence || "*"
  render(partial:"admin/shared/forms/slug_field", locals: {
    f: self,
    method: method,
    options: options,
    preview_value: preview_value,
    pattern: (pattern || "/blog-example/*")
  })
end