2017-04-21 114 views
0

我創建了一個表單,但我有問題提交表單,它沒有找到正確的路由,我確信這是一個簡單的修復,我只是不看到它。路由錯誤提交時沒有路由匹配[POST]

以下是相關文件:

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

必須路由指向控制器和動作

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

我已經改變了路線,但我仍然得到'路由錯誤 沒有路由匹配[POST]「/ orders_and_returns /新」'任何建議? –

+0

然後改變發表 – Iceman

相關問題