我似乎被卡在Ruby on Rails的教程中,我不斷收到這是在標題這篇文章的,這是錯誤:路由錯誤的路由匹配[POST]「/聯繫人/新
路由錯誤沒有路由匹配[POST] 「/聯繫人/新」
應用程序/視圖/聯繫人/ new.html.erb
<div class="container">
<div class="rpw">
<h3 class="text-center">Contact Us</h3>
<div class="col-md-4 col-md-offset-4">
<%= flash[:notice] %>
<div class="well">
<%= form_for "/contacts" do |f| %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.text_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :comments %>
<%= f.text_area :comments, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-success' %>
<% end %>
</div>
</div>
</div>
的routes.rb
Rails.application.routes.draw do
root to: 'pages#home'
get 'about', to: 'pages#about'
resources :contacts
末
contacts_controller.rb
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(contact_params)
if @contact.save
redirect_to new_contact_path, notice: "Message sent."
else
redirect_to new_contact_path, notice: "Error occured"
end
end
private
def contact_params
params.require(:contact).permit(:name, :email, :comments)
end
末
contact.rb
class Contact < ActiveRecord::Base
末
我不確定我在哪裏出錯了。請幫幫我。我一直在嘗試解決這個問題幾天。
試<(%)=的form_for @contact做| F | %> –