Ben John Bagley

Joined

3,260 Experience
22 Lessons Completed
1 Question Solved

Activity

I have created a form but I'm having issues submitting the form, it's not getting the right route, I'm sure this is a simple fix, I'm just not seeing it.

Here are the relevant files:

new.html.erb

<%= content_for :title, "Orders & Returns" %>

<div class="title">
  <h1>Orders &amp; Returns</h1>
  <p>In order for us to initialise a return of any order, first we need some information.</p>
</div>

<%= simple_form_for("/orders_and_returns/thank_you") do |f| %>
  <%= f.input :order_number,
              error: false,
              label: false,
              required: true,
              placeholder: "Order Number" %>

  <%= f.input :billing_name,
              error: false,
              label: false,
              required: true,
              placeholder: "Billing Name" %>

  <%= f.input :email,
              error: false,
              label: false,
              required: true,
              placeholder: "Email Address" %>

  <%= f.input :message,
              as: :text,
              error: false,
              label: false,
              required: true,
              placeholder: "Why do you wish to initialise a return?" %>

  <div class="hidden">
    <%= f.input :nickname,
                label: false,
                required: false,
                placeholder: "Captcha" %>
  </div>

  <%= f.submit "Submit",
               class: "button-border center-100" %>
<% end %>

thank_you.html.erb

<% content_for :title, "Thank You" %>

<div class="title">
  <h3>Thank you for your message!</h3>
  <p>We shall get back to you soon.</p>
</div>

<section class="text-center">
  <%= link_to "Go back home", root_path %>
</section>

order_and_returns_controller.rb

class OrdersAndReturnsController < ApplicationController
  def new
  end

  def thank_you
    @order_name   =   params[:order_name]
    @billing_name =   params[:billing_name]
    @email        =   params[:email]
    @message      =   params[:message]

    OrdersAndReturnMailer.orders_and_returns(@order_number, @billing_name, @email, @message).deliver_now
  end
end

orders_and_return_mailer.rb

class OrdersAndReturnMailer < ApplicationMailer

  def orders_and_returns(order_number, billing_name, email, message)
    @order_number = order_number
    @billing_name = billing_name
    @email        = email
    @message      = message

    mail(
         from: email,
         to: ENV['order_email'],
         subject: "You have a new return query from #{email}"
         )
    end
  end

end

routes.rb

get 'orders_and_returns/new' => 'orders_and_returns#new'
post 'orders_and_returns/thank_you' => 'orders_and_returns#thank_you'

Not sure what I'm missing here, any help would be appreciated.

EDIT

All routes:

rails routes
                      Prefix Verb   URI Pattern                             Controller#Action
        new_customer_session GET    /customers/sign_in(.:format)            devise/sessions#new
            customer_session POST   /customers/sign_in(.:format)            devise/sessions#create
    destroy_customer_session DELETE /customers/sign_out(.:format)           devise/sessions#destroy
       new_customer_password GET    /customers/password/new(.:format)       devise/passwords#new
      edit_customer_password GET    /customers/password/edit(.:format)      devise/passwords#edit
           customer_password PATCH  /customers/password(.:format)           devise/passwords#update
                             PUT    /customers/password(.:format)           devise/passwords#update
                             POST   /customers/password(.:format)           devise/passwords#create
cancel_customer_registration GET    /customers/cancel(.:format)             devise/registrations#cancel
   new_customer_registration GET    /customers/sign_up(.:format)            devise/registrations#new
  edit_customer_registration GET    /customers/edit(.:format)               devise/registrations#edit
       customer_registration PATCH  /customers(.:format)                    devise/registrations#update
                             PUT    /customers(.:format)                    devise/registrations#update
                             DELETE /customers(.:format)                    devise/registrations#destroy
                             POST   /customers(.:format)                    devise/registrations#create
   new_customer_confirmation GET    /customers/confirmation/new(.:format)   devise/confirmations#new
       customer_confirmation GET    /customers/confirmation(.:format)       devise/confirmations#show
                             POST   /customers/confirmation(.:format)       devise/confirmations#create
         new_customer_unlock GET    /customers/unlock/new(.:format)         devise/unlocks#new
             customer_unlock GET    /customers/unlock(.:format)             devise/unlocks#show
                             POST   /customers/unlock(.:format)             devise/unlocks#create
                        root GET    /                                       landing#show
      orders_and_returns_new GET    /orders_and_returns/new(.:format)       orders_and_returns#new
orders_and_returns_thank_you POST   /orders_and_returns/thank_you(.:format) orders_and_returns#thank_you
                    contacts POST   /contacts(.:format)                     contacts#create
                 new_contact GET    /contacts/new(.:format)                 contacts#new
             dashboard_index GET    /dashboard(.:format)                    dashboard#index
                             POST   /dashboard(.:format)                    dashboard#create
               new_dashboard GET    /dashboard/new(.:format)                dashboard#new
              edit_dashboard GET    /dashboard/:id/edit(.:format)           dashboard#edit
                   dashboard GET    /dashboard/:id(.:format)                dashboard#show
                             PATCH  /dashboard/:id(.:format)                dashboard#update
                             PUT    /dashboard/:id(.:format)                dashboard#update
                             DELETE /dashboard/:id(.:format)                dashboard#destroy

EDIT 2 - Terminal Logs

Started POST "/orders_and_returns/new" for ::1 at 2017-04-21 22:18:12 +0100

ActionController::RoutingError (No route matches [POST] "/orders_and_returns/new"):

actionpack (5.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:53:in `call'
web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.4.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `catch'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.2) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.2) lib/rails/engine.rb:522:in `call'
puma (3.8.2) lib/puma/configuration.rb:224:in `call'
puma (3.8.2) lib/puma/server.rb:600:in `handle_request'
puma (3.8.2) lib/puma/server.rb:435:in `process_client'
puma (3.8.2) lib/puma/server.rb:299:in `block in run'
puma (3.8.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
  Rendering /Users/benclarke/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout
  Rendering /Users/benclarke/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered /Users/benclarke/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.1ms)
  Rendered collection of /Users/benclarke/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/routes/_route.html.erb [34 times] (8.7ms)
  Rendered /Users/benclarke/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.5ms)
  Rendering /Users/benclarke/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered /Users/benclarke/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.6ms)
  Rendered /Users/benclarke/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (98.0ms)