title: Setting contact form
body: <p>I am setting a contact form. But it doesn't work. I got an error message like</p>
  
  <pre><code>SQLite3::ConstraintException: contacts.name may not be NULL: INSERT INTO "contacts" ("content", "created_at", "email", "name", "updated_at") VALUES (?, ?, ?, ?, ?)
  </code></pre>
  
  <p>.</p>
  
  <p>It seems like this error comes from controller setting because I get this error message before the form shows. I mean I couldn't see any form on static_pages/contact.
   Could you give me some advice?</p>
  
  <p>☆static_pages_controller</p>
  
  <pre><code> def contact
    @contact = Contact.new(params[:contact])
    if @contact.save
      ContactMailer.sent(@contact).deliver
      redirect_to :action =&gt; :contact, :notice =&gt; 'お問い合わせありがとうございました。'
    else
      render :action =&gt; :contact, :alert =&gt; 'お問い合わせに不備があります。'
    end
  end
  </code></pre>
  
  <p>☆contact.html.erb</p>
  
  <pre><code>&lt;h1&gt;お問い合わせフォーム&lt;/h1&gt;
  
  &lt;%= form_for(@contact) do |f| %&gt;
    &lt;% if @contact.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@contact.errors.count, "error") %&gt; prohibited this contact from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% @contact.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :name %&gt;&lt;br /&gt;
      &lt;%= f.string_field :name %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :email %&gt;&lt;br /&gt;
      &lt;%= f.string_field :email %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :content %&gt;&lt;br /&gt;
      &lt;%= f.text_field :content %&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>☆routes.rb</p>
  
  <pre><code> get "static_pages/contact"
    post"static_pages/contact"
  </code></pre>
  
  <p>☆contact.rb</p>
  
  <pre><code>class Contact &lt; ActiveRecord::Base
    attr_accessible :name, :email, :content
  end
  </code></pre>
  
  <p>☆contact_mailer.rb</p>
  
  <pre><code>class ContactMailer &lt; ActionMailer::Base
    default from: "from@example.com"
  
    def sent(contact)
      @contact = contact
  
      mail(:to =&gt; "xxxxxxxxx@gmail.com", :subject =&gt; 'TsundokuBuster発お問い合わせ')
    end
  end
  </code></pre>