# Automating form creation

**URL:** <https://www.ruby-forum.com/t/automating-form-creation/111670>\
**Category:** Rails\
**Created:** [August 9, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/automating-form-creation/111670 "2007-08-09T17:35:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmanueloga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecae2f/32.png) [@emmanueloga](https://www.ruby-forum.com/u/emmanueloga)\
**Post date:** [August 9, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/automating-form-creation/111670/1 "2007-08-09T17:35:53Z")

</div>

Hi! I want to auto-select the form method in my form creator to automate  
the creation of forms. Do you know any better way to do this? :

(I want a better solution for this: form\_method f, @resource, attribute  
)

The erb form:

\<% form\_for(:resource,  
:url =\> resource\_path,  
:html =\> { :method =\> :put }) do |f| %\>

\<% resource\_columns.each\_with\_index do |attribute, index| -%\>

```
<%= resource_titles[index] -%>
<%= form_method f, @resource, attribute -%>

```

\<% end -%\>

\<% end -%\>

The helper:

# This Helper returns the apropiate form method

# for the resource and attribute

def form\_method form, resource, attribute

```
case resource.column_for_attribute(attribute).type

when :string : form.text_field(attribute)
when :text : form.text_area(attribute)
when :integer : form.text_field(attribute)
when :float : form.text_field(attribute)
when :decimal : form.text_field(attribute)
when :datetime : form.text_field(attribute)
when :timestamp : form.text_field(attribute)
when :time : form.text_field(attribute)
when :date : form.text_field(attribute)
when :binary : form.check_box(attribute)
when :boolean : form.check_box(attribute)

end

```

end

Thanks!

[emmanueloga.blogspot.com](http://emmanueloga.blogspot.com)
