エラー Routing Error No route matches [POST] …
解決したいこと
独学でプログラミング学習を行って、2ヶ月の初心者なのですが、
はじめてのオリジナルアプリでチャット機能実装中にRouting Errorエラーが出てしまいました。
ルーティングやコントローラーを調べたのですが、解決が出来ず、みなさまのお力をお借りしたいです。
何卒よろしくお願いいたします。
発生している問題・エラー
Routing Error
No route matches [POST] "/schools/new"
該当するソースコード
root GET / homes#index
homeroom_comments GET /homerooms/:homeroom_id/comments(.:format) comments#index
POST /homerooms/:homeroom_id/comments(.:format) comments#create
new_homeroom_comment GET /homerooms/:homeroom_id/comments/new(.:format) comments#new
edit_homeroom_comment GET /homerooms/:homeroom_id/comments/:id/edit(.:format) comments#edit
homeroom_comment GET /homerooms/:homeroom_id/comments/:id(.:format) comments#show
PATCH /homerooms/:homeroom_id/comments/:id(.:format) comments#update
PUT /homerooms/:homeroom_id/comments/:id(.:format) comments#update
DELETE /homerooms/:homeroom_id/comments/:id(.:format) comments#destroy
search_homerooms GET /homerooms/search(.:format) homerooms#search
homerooms GET /homerooms(.:format) homerooms#index
POST /homerooms(.:format) homerooms#create
new_homeroom GET /homerooms/new(.:format) homerooms#new
edit_homeroom GET /homerooms/:id/edit(.:format) homerooms#edit
homeroom GET /homerooms/:id(.:format) homerooms#show
PATCH /homerooms/:id(.:format) homerooms#update
PUT /homerooms/:id(.:format) homerooms#update
DELETE /homerooms/:id(.:format) homerooms#destroy
school_messages GET /schools/:school_id/messages(.:format) messages#index
POST /schools/:school_id/messages(.:format) messages#create
new_school_message GET /schools/:school_id/messages/new(.:format) messages#new
edit_school_message GET /schools/:school_id/messages/:id/edit(.:format) messages#edit
school_message GET /schools/:school_id/messages/:id(.:format) messages#show
PATCH /schools/:school_id/messages/:id(.:format) messages#update
PUT /schools/:school_id/messages/:id(.:format) messages#update
DELETE /schools/:school_id/messages/:id(.:format) messages#destroy
schools GET /schools(.:format) schools#index
POST /schools(.:format) schools#create
new_school GET /schools/new(.:format) schools#new
edit_school GET /schools/:id/edit(.:format) schools#edit
school GET /schools/:id(.:format) schools#show
PATCH /schools/:id(.:format) schools#update
PUT /schools/:id(.:format) schools#update
DELETE /schools/:id(.:format) schools#destroy
config/routes.rb
Rails.application.routes.draw do
devise_for :teachers, controllers: {
sessions: 'teachers/sessions',
passwords: 'teachers/passwords',
registrations: 'teachers/registrations'
}
devise_for :students, controllers: {
sessions: 'students/sessions',
passwords: 'students/passwords',
registrations: 'students/registrations'
}
root to: "homes#index"
resources :homerooms do
resources :comments do
end
collection do
get 'search'
end
end
resources :schools do
resources :messages
end
end
app/controllers/schools_controller.rb
class SchoolsController < ApplicationController
def new
@messages = Message.all
end
def create
@message = Comment.new(text: params[:messages])
if @message.save
ActionCable.server.broadcast 'messages_channel', content: @messages
end
end
end
app/views/schools/new.html.erb
<div class="main-container">
<div class="container">
<div class="comments_lists">
<% @messages.each do |message| %>
<div class="message-date">
<%= l message.created_at %>
</div>
<div class="message-comment">
<%= message.comment %>
</div>
<%= image_tag message.image, class: "message-img" if message.image.attached? %>
<% end %>
</div>
</div>
</div>
<%= form_with(model: @message, url: new_school_path, class: 'comment-form-sp', local: true) do |form| %>
<div class="form-input-sp">
<%= form.text_area :message, class: 'input-comment', placeholder: "例)質問内容:" %>
</div>
<label class="form-image">
<span class="image-file">画像</span>
<%= form.file_field :image, class: 'hidden' %>
</label>
<div class='actions-sp2'>
<%= form.submit "送信", class: 'comment-red-btn-sp'%>
</div>
<% end %>
</div>
</div>
0 likes