Class: SliderInput

Inherits:
Formtastic::Inputs::StringInput
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers, FormSlider::Helper
Defined in:
app/inputs/slider_input.rb

Overview

custom input for formtastic can be used like this:

f.input :score, as: :slider, min: 1, max: 5

Instance Method Summary collapse

Methods included from FormSlider::Helper

#slider_label, #slider_options

Instance Method Details

#to_htmlObject



11
12
13
14
15
16
17
18
19
# File 'app/inputs/slider_input.rb', line 11

def to_html
  value = object.send(method) || options[:min]
  label = slider_label(method, options)
  slider =  :div, '', slider_options(method, options)
  output = builder.input(method, input_options.merge(input_html: { value: value }, wrapper_html: { class: "slider-container" }))
  output.gsub! /(<label).*(<\/label>)/, label
  output.insert output.index(/(<input)/), slider
  output.html_safe
end