Automatic form tag helpers given the attribute type

Hi. I need to get the apropiate tag helper given a resource attribute.
I’m pretty much sure rails already has something to do this, but i don’t
remember where. My ugly solution is this:

def standard_form_method form, resource, attribute
  case resource.column_for_attribute(attribute).type
  when :text
    form.text_area(attribute)
  when :binary, :boolean
    form.check_box(attribute)
  else
  #when :string, :integer, :float, :decimal
  #when :datetime, :timestamp, :time, :date
    form.text_field(attribute)
  end
end

then in erb you can call, inside a form

(EDIT.RHTML)

<% form_for :resource,
:url => resource_path(@resource),
:html => { :method => :put } do |f| -%>

<% @resource.each_attribute do |attribute| -%>
<% ar_form_method(f, @resource, attribute) -%>
<% end -%>
<%= submit_tag “Send” %>
<% end %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs