<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <generator>Persumi - Level up your writing and blogging with AI</generator>
  <category label="Blog" scheme="http://persumi.com/u/fredwu/tech/e/blog" term="blog"/>
  <category label="Tech" scheme="http://persumi.com/u/fredwu/tech" term="tech"/>
  <link href="http://persumi.com/u/fredwu/tech/e/blog/t/forms"/>
  <link href="http://persumi.com/u/fredwu/tech/e/blog/t/forms/feed/rss"/>
  <link rel="self" href="http://persumi.com/u/fredwu/tech/e/blog/t/forms/feed/atom"/>
  <author>
    <name>Fred Wu</name>
    <email>ifredwu@gmail.com</email>
    <uri>http://persumi.com/u/fredwu</uri>
  </author>
  <subtitle/>
  <id>http://persumi.com/u/fredwu/tech/e/blog/t/forms</id>
  <title>Blog (forms) - Fred Wu&apos;s Tech</title>
  <updated>2026-05-01T23:26:20.238075Z</updated>
  <entry>
    <content type="html">&lt;![CDATA[&lt;p&gt;
Web applications normally have many forms. Building forms is always a mind-boggling task because it involves repetition and chaos.&lt;/p&gt;
&lt;p&gt;
A shortcut is to use a form builder / &lt;a href=&quot;http://en.wikipedia.org/wiki/Domain-specific_language&quot;&gt;DSL&lt;/a&gt;, such as &lt;a href=&quot;http://github.com/justinfrench/formtastic&quot;&gt;Formtastic&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;
As I am using Rails 3, and the Rails 3 port of Formtastic isn’t complete yet, I thought I’d just use the plain vanilla Rails built-in form helper.&lt;/p&gt;
&lt;p&gt;
First of all, I am using &lt;a href=&quot;http://haml-lang.com/&quot;&gt;Haml&lt;/a&gt; instead of ERb. Already, I got the out-of-box clean looking Haml markup.&lt;/p&gt;
&lt;p&gt;
Some of you might not be aware of the fact that Rails’ built-in form helper already does i18n support.&lt;/p&gt;
&lt;p&gt;
If you have the following form:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;ruby language-ruby&quot;&gt;-form_for(@post) do |f|
  =f.label :title
  =f.text_field :title
  =f.label :body
  =f.text_area :body
  =f.submit&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
You can simply translate the labels as such in &lt;code class=&quot;inline&quot;&gt;config/locales/en.yml&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;yaml language-yaml&quot;&gt;helpers:
  label:
    post:
      title: &apos;Post Title&apos;
      body: &apos;Post Content&apos;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Better yet, I am using &lt;a href=&quot;http://r18n.rubyforge.org/&quot;&gt;r18n&lt;/a&gt; instead of i18n, so I can instead translate them in &lt;code class=&quot;inline&quot;&gt;app/i18n/en.yml&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;yaml language-yaml&quot;&gt;helpers:
  label:
    post:
      title: Post Title
      body: Post Content&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Alternatively, instead of placing the translation strings under &lt;code class=&quot;inline&quot;&gt;helpers.label&lt;/code&gt;, you may place them directly under your models, i.e. &lt;code class=&quot;inline&quot;&gt;activemodel.attribute&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;
If you’re using the &lt;a href=&quot;http://github.com/rails/rails/tree/2-3-stable&quot;&gt;Rails 2.3 stable branch&lt;/a&gt; from Github, you can also use the built-in i18n support. Although instead of &lt;code class=&quot;inline&quot;&gt;helpers.label&lt;/code&gt;, you use &lt;code class=&quot;inline&quot;&gt;views.labels&lt;/code&gt;, as seen in &lt;a href=&quot;http://github.com/rails/rails/commit/bef968d37942bfb2b7a59fca0e4451e096197c0a&quot;&gt;this commit&lt;/a&gt;.&lt;/p&gt;
]]&gt;</content>
    <published>2010-03-08T05:41:00.000000Z</published>
    <category label="Blog" scheme="http://persumi.com/u/fredwu/tech/e/blog" term="blog"/>
    <category label="Tech" scheme="http://persumi.com/u/fredwu/tech" term="tech"/>
    <link href="http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-making-i18n-forms-the-easy-way"/>
    <author>
      <name>Fred Wu</name>
      <email>ifredwu@gmail.com</email>
      <uri>http://persumi.com/u/fredwu</uri>
    </author>
    <id>http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-making-i18n-forms-the-easy-way</id>
    <title>[Rails Tip] Making i18n Forms, the Easy Way</title>
    <updated>2010-03-08T05:41:00.000000Z</updated>
  </entry>
</feed>