路由错误提交时没有路由匹配[POST]

时间:2017-04-21 16:17:42

标签: ruby-on-rails ruby-on-rails-5 actionmailer

我创建了一个表单但是我在提交表单时遇到了问题,它没有找到正确的路线,我确信这是一个简单的修复,我只是没有看到它。

以下是相关文件:

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'
post 'orders_and_returns/thank_you'

不确定我在这里缺少什么,我们将不胜感激。

1 个答案:

答案 0 :(得分:1)

您必须将路线指向控制器和操作

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