views:

98

answers:

1

In my Rails 3 application I have a typical 'Email this to a friend' form that has yours/friend's email and name fields. Each of them must be validated and error messages must be displayed, in a fashion similar to ActiveRecord forms:

  <%= form_tag %>
    <div class="fields">
      <%= label_tag :friends_name %>
      <%= text_field_tag :friends_name, params[:friends_name] %>
      <%= label_tag :friends_email %>
      <%= text_field_tag :friends_email, params[:friends_email] %>
    </div>
    <div class="fields">
      <%= label_tag :your_name %>
      <%= text_field_tag :your_name, params[:your_name] %>
      <%= label_tag :your_email %>
      <%= text_field_tag :your_email, params[:your_email] %>
    </div>
    <div class="fields">
      <%= label_tag :message %>
      <%= text_area_tag :message, params[:message] %>
    </div>
    <%= submit_tag 'Send'%>
  </form>

What would be the 'Rails way' of doing this?

A: 

I found the answer in the episode #219 - Active Model on railscasts.com

Vincent