みなさま、いつもご教授いただきありがとうございます。
#困っていること
現状、contact_formを作成していてルーティングエラーになり困っています。
(Routing Error、No route matches [POST] "/")
主観的にはroutesが違うのかと思っているのですが、もしわかる方がいればご教授いただけないでしょうか。
宜しくお願い申し上げますm(_ _)m
コード
コード HomesController class HomesController < ApplicationController def top @contact = Contact.new end def about end def new @contact = Contact.new end def create @contact = Contact.new(contact_params) if @contact.save flash[:success] = "送信しました" redirect_to root_path else render "about" end end private def contact_params params.require(:contact).permit(:name, :email, :description) end end
コード homes/top view <h2 class="text-center my-5 pt-5"><span class="text-muted border-bottom border-dark pb-2">CONTACT</span></h2> <%= form_for(@contact) do |f| %> <%= f.text_field :name , placeholder: "お名前", class: 'form-control mt-4', rows:4%> <%= f.email_field :email, class: 'form-control mt-4', rows:4, placeholder: "メールアドレス"%> <%= f.text_area :description, class: 'form-control mt-4', rows:4, cols:5, placeholder: "メッセージ" %> <p class="text-center"><%= f.submit "送信する", class: "btn btn-primary mb-4 btn-lg mt-3" %></p> <% end %>
コード routes Rails.application.routes.draw do root to:'homes#top' get '/about',to:'homes#about' post 'add', to:'homes#create' resources :homes resources :contacts end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。