title: Rails: The action 'index' could not be found for ContactsController
body: <p>I'm building out a contact form for a Rails App and am getting the following error:</p>
  
  <pre><code>'The action 'index' could not be found for ContactsController'
  </code></pre>
  
  <p>I'm confused because I've built contact forms before, the same way and with no problem. It seems odd because I'm not using or referencing an index.html.erb or index method in my ContactsController at all? Please find the files below:</p>
  
  <p>contacts_controller.rb</p>
  
  <pre><code>  class ContactsController &lt; ApplicationController
  
          def new
              @contact = Contact.new
          end
  
          def create
              @contact = Contact.new(contact_params)
  
              if @contact.save
                  flash[:success] = "Message Sent!"
                  redirect_to new_contact_path
              else
                  flash[:danger] = "Error occurred"
                  redirect_to new_contact_path
              end
          end
  
          private
              def contact_params
                  params.require(:contact).permit(:name, :phone, :email, :comments)
              end
      end
  </code></pre>
  
  <p>models/contact.rb</p>
  
  <pre><code>class Contact &lt; ActiveRecord::Base
      validates :name, presence: true
      validates :email, presence: true
  
      after_create :send_email
  
      private
          def send_email
              ContactMailer.contact_email(self).deliver
          end
  end
  </code></pre>
  
  <p>mailers/contact_mailer.rb</p>
  
  <pre><code>class ContactMailer &lt; ActionMailer::Base
      default to: 'example@example.com.au'
  
      def contact_email(contact)
          @contact = contact
  
          mail(from: @contact.email, subject: 'Contact Form Message').deliver
      end
  
  end
  </code></pre>
  
  <p>views/layouts/application.html.erb</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;RunpixelrunWebsite&lt;/title&gt;
    &lt;%= stylesheet_link_tag    'application', media: 'all' %&gt;
    &lt;%= javascript_include_tag 'application' %&gt;
    &lt;%= csrf_meta_tags %&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div class="container"&gt;
  
      &lt;% flash.each do |key, value| %&gt;
      &lt;div class="alert alert-&lt;%= key %&gt; alert-dismissable"&gt;
        &lt;button type="button" class ="close" data-dismiss="alert" aria-label="Close"&gt;&lt;span aria-hidden = "true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
        &lt;%= value %&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
  
  &lt;%= yield %&gt;
    &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>views/contacts/new.html.erb</p>
  
  <pre><code>&lt;div class="row"&gt; 
      &lt;div class="col-md-4 col-md-offset-4"&gt;
          &lt;div class="well"&gt;
              &lt;%= form_for @contact do |f| %&gt;
                  &lt;div class="form-group"&gt;
                      &lt;%= f.label :name %&gt;
                      &lt;%= f.text_field :name, class: 'form-control' %&gt;
                  &lt;/div&gt;
  
                  &lt;div class="form-group"&gt;
                      &lt;%= f.label :phone %&gt;
                      &lt;%= f.text_field :phone, class: 'form-control' %&gt;
                  &lt;/div&gt;
  
                  &lt;div class="form-group"&gt;
                      &lt;%= f.label :email %&gt;
                      &lt;%= f.email_field :email, class: 'form-control' %&gt;
                  &lt;/div&gt;
  
                  &lt;div class="form-group"&gt;
                      &lt;%= f.label :comments %&gt;
                      &lt;%= f.text_area :comments, class: 'form-control' %&gt;
                  &lt;/div&gt;
  
                  &lt;%= f.submit "Submit", class: "btn btn-default" %&gt;
              &lt;% end %&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>routes.rb</p>
  
  <pre><code>Rails.application.routes.draw do
  
    resources :contacts
  
    root 'contacts#new'
  </code></pre>
  
  <p>log:</p>
  
  <pre><code>Started POST "/contacts" for 10.240.0.44 at 2015-11-19 05:25:05 +0000
  Cannot render console from 10.240.0.44! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  Processing by ContactsController#create as HTML
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"ruEgewytZuJBEBh2bHoJJWj9uY4dp69JQOVFyl/V+v9l+dBTi3ZQn1Iq8Mb4D6bUSLDAvG9dNMSCKLVrfsDAKw==", "contact"=&gt;{"name"=&gt;"asdf", "phone"=&gt;"asdf", "email"=&gt;"asdfadsf@sfdgasd", "comments"=&gt;"asdfasdf"}, "commit"=&gt;"Submit"}
     (0.1ms)  begin transaction
    SQL (0.4ms)  INSERT INTO "contacts" ("name", "phone", "email", "comments", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)  [["name", "asdf"], ["phone", "asdf"], ["email", "asdfadsf@sfdgasd"], ["comments", "asdfasdf"], ["created_at", "2015-11-19 05:25:05.377425"], ["updated_at", "2015-11-19 05:25:05.377425"]]
  DEPRECATION WARNING: `#deliver` is deprecated and will be removed in Rails 5. Use `#deliver_now` to deliver immediately or `#deliver_later` to deliver through Active Job. (called from send_email at /home/ubuntu/workspace/runpixelrun_website/app/models/contact.rb:9)
    Rendered contact_mailer/contact_email.html.erb (1.6ms)
  
  Sent mail to example@example.com.au (30014.0ms)
  Date: Thu, 19 Nov 2015 05:25:05 +0000
  From: asdfadsf@sfdgasd
  To: example@example.com.au
  Message-ID: &lt;564d5d319e2ca_56b22a3201c112db@runpixelrun-runpixelrun_projects-2170203.mail&gt;
  Subject: Contact Form Message
  Mime-Version: 1.0
  Content-Type: text/html;
   charset=UTF-8
  Content-Transfer-Encoding: 7bit
  
  &lt;!DOCTYPE Html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;p&gt;New message from RuNpiXelruN's Contact Form!, from asdf, asdfadsf@sfdgasd&lt;/p&gt;
          &lt;/br&gt;
          &lt;p&gt;asdf&lt;/p&gt;
          &lt;p&gt;asdf&lt;/p&gt;
          &lt;p&gt;asdfasdf&lt;/p&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  
  ContactMailer#contact_email: processed outbound mail in 30263.5ms
  
  Sent mail to example@example.com.au (30006.4ms)
  Date: Thu, 19 Nov 2015 05:25:05 +0000
  From: asdfadsf@sfdgasd
  To: example@example.com.au
  Message-ID: &lt;564d5d319e2ca_56b22a3201c112db@runpixelrun-runpixelrun_projects-2170203.mail&gt;
  Subject: Contact Form Message
  Mime-Version: 1.0
  Content-Type: text/html;
   charset=UTF-8
  Content-Transfer-Encoding: 7bit
  
  &lt;!DOCTYPE Html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;p&gt;New message from RuNpiXelruN's Contact Form!, from asdf, asdfadsf@sfdgasd&lt;/p&gt;
          &lt;/br&gt;
          &lt;p&gt;asdf&lt;/p&gt;
          &lt;p&gt;asdf&lt;/p&gt;
          &lt;p&gt;asdfasdf&lt;/p&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
     (18.5ms)  commit transaction
  Redirected to http://runpixelrun-projects-runpixelrun.c9users.io:8080/contacts/new
  Completed 302 Found in 60313ms (ActiveRecord: 19.0ms)
  
  
  Started GET "/contacts" for 10.240.0.45 at 2015-11-19 05:28:48 +0000
  Cannot render console from 10.240.0.45! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  
  AbstractController::ActionNotFound (The action 'index' could not be found for ContactsController):
    actionpack (4.2.4) lib/abstract_controller/base.rb:132:in `process'
    actionview (4.2.4) lib/action_view/rendering.rb:30:in `process'
    actionpack (4.2.4) lib/action_controller/metal.rb:196:in `dispatch'
    actionpack (4.2.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
    actionpack (4.2.4) lib/action_controller/metal.rb:237:in `block in action'
    actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `call'
    actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
    actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:45:in `serve'
    actionpack (4.2.4) lib/action_dispatch/journey/router.rb:43:in `block in serve'
    actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `each'
    actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `serve'
    actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:821:in `call'
    rack (1.6.4) lib/rack/etag.rb:24:in `call'
    rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
    rack (1.6.4) lib/rack/head.rb:13:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/flash.rb:260:in `call'
    rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
    rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
    activerecord (4.2.4) lib/active_record/query_cache.rb:36:in `call'
    activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
    activerecord (4.2.4) lib/active_record/migration.rb:377:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
    activesupport (4.2.4) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
    activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
    activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
    actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
    web-console (2.2.1) lib/web_console/middleware.rb:31:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
    railties (4.2.4) lib/rails/rack/logger.rb:38:in `call_app'
    railties (4.2.4) lib/rails/rack/logger.rb:20:in `block in call'
    activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
    activesupport (4.2.4) lib/active_support/tagged_logging.rb:26:in `tagged'
    activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `tagged'
    railties (4.2.4) lib/rails/rack/logger.rb:20:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
    rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
    rack (1.6.4) lib/rack/runtime.rb:18:in `call'
    activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
    rack (1.6.4) lib/rack/lock.rb:17:in `call'
    actionpack (4.2.4) lib/action_dispatch/middleware/static.rb:116:in `call'
    rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
    railties (4.2.4) lib/rails/engine.rb:518:in `call'
    railties (4.2.4) lib/rails/application.rb:165:in `call'
    rack (1.6.4) lib/rack/lock.rb:17:in `call'
    rack (1.6.4) lib/rack/content_length.rb:15:in `call'
    rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
    /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
    /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
    /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
  
  
    Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb within rescues/layout (0.6ms)
  </code></pre>
  
  <p>It all looks like it's sending and being called ok? </p>
  
  <p>Thanks</p>
  
  <p>Justin</p>