Module: Stay::FormHelper

Defined in:
lib/stay/helper.rb

Instance Method Summary collapse

Instance Method Details

#generate_form(object, field, type = :text_field) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/stay/helper.rb', line 3

def generate_form(object, field, type = :text_field)
  form_for(object, remote: true, format: :json) do |f|
    if type == :tiny_mce || type.is_a?(Array)
      if type == :tiny_mce
        w = "100%"
        h = "200px"
      else
        w = type[2] || "100%"
        h = type[3] || "200px"
      end
      object_id = (object.is_a?(Array) ? object.last : object).id
      f.send(:text_area, field, class: "stay-input stay-tiny-mce", id: "stay-mce-#{ object_id }", style: "width:#{w}; height:#{h};")
    else
      f.send(type, field, class: "stay-input")
    end
  end
end