Module: Ext::FormHelpers::Helpers

Defined in:
lib/ext/form_helpers.rb

Instance Method Summary collapse

Instance Method Details

#form_for(entity, opts) ⇒ Object

No relations yet



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ext/form_helpers.rb', line 26

def form_for(entity, opts)
  entity = entity.new if entity.kind_of? Class
  form({:method=>:post}.merge(opts)) do
    entity.attributes.each do |prop|
      unless /^id$|_id$/.match prop[0].to_s
        input_name = prop[0]
        label prop[0].to_s, :for=>input_name; br
        input :type=>'text', :name=>input_name, :value=>entity.send(prop[0]); br
      end
    end

    input :type=>:hidden, :name=>'id', :value=>entity.id if entity.id
    input :type=>:submit
  end
end