title: validations for the model form
body: <p>I have got a form which is generated by model object. </p>
  
  <pre><code>&lt;%= form_for(@pages) do |f| %&gt;
  
    &lt;p&gt;
      &lt;%= f.label :title %&gt;&lt;br /&gt;
      &lt;%= f.text_field :title %&gt;
    &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Here is the controller method for this:</p>
  
  <pre><code>def new
      @pages = Page.new
  
      respond_to do |format|
      format.html  # new.html.erb
      format.json  { render :json =&gt; @post }
      end
    end
  </code></pre>
  
  <p>Here is the model code:</p>
  
  <pre><code>class Page &lt; ActiveRecord::Base
  validates :title, :presence =&gt; true
  end
  </code></pre>
  
  <p>Now, how can I validate the form on submission.(i know that submit button is not there, i will add it later). I have used <code>&lt;%= f.error_messages %&gt;</code> in the form but it is giving me error : </p>
  
  <pre><code>NoMethodError in Pages#new
  
  Showing C:/rorapp/app/views/pages/_form.html.erb where line #2 raised:
  
  undefined method `error_messages' for #&lt;ActionView::Helpers::FormBuilder:0x49b9ca8&gt;
  Extracted source (around line #2):
  
  1: &lt;%= form_for(@pages) do |f| %&gt;
  2:   &lt;%= f.error_messages %&gt;
  3:   &lt;p&gt;
  4:     &lt;%= f.label :title %&gt;&lt;br /&gt;
  5:     &lt;%= f.text_field :title %&gt;
  Trace of template inclusion: app/views/pages/new.html.erb
  
  Rails.root: C:/rorapp
  
  Application Trace | Framework Trace | Full Trace
  app/views/pages/_form.html.erb:2:in `block in _app_views_pages__form_html_erb__975660997_39217440'
  app/views/pages/_form.html.erb:1:in `_app_views_pages__form_html_erb__975660997_39217440'
  app/views/pages/new.html.erb:2:in `_app_views_pages_new_html_erb___256256638_47476836'
  app/controllers/pages_controller.rb:11:in `new'
  Request
  
  Parameters:
  
  {"title"=&gt;"",
   "author"=&gt;"",
   "email"=&gt;"",
   "body"=&gt;"",
   "reference"=&gt;"Google"}
  Show session dump
  
  Show env dump
  
  Response
  
  Headers:
  
  None
  </code></pre>
  
  <p>How can I validate it? </p>