前提・実現したいこと
こんにちは。
オープンチャットアプリのチャット画面でメッセージを送信できるようにしたいです。
オープンチャットなので、create.html.erbは作らずにshow.html.erbに直接メッセージを反映させたいのですがうまくいきません。
発生している問題・エラーメッセージ
Routing Error No route matches [POST] "/rooms/show"
該当のソースコード
routes.rb Rails.application.routes.draw do devise_for :users, controllers:{ registrations: 'users/registrations' } root to: "home#top" resources :homes, only: [:top,:about] resources :rooms, only: [:show,:new,:create] resources :users, only: [:show,:edit,:update] mount ActionCable.server => '/cable' end rooms_controller.rb class RoomsController < ApplicationController def show @messages = Message.all end def new @message = Message.new end def create @message = Message.create(content: message_params[:content], user_id: current_user.id) @message.save redirect_to root_path end private def message_params params.require('message').permit(:content) end end rooms/show.html.erb <div class = "container"> <h1>Chat room</h1> <div id = "messages"> <ul class = "list-group"> <%= render @messages %> </ul> </div> <%= form_with(model: @message, local: true) do |f| %> <%= f.text_field :content %> <%= f.submit '送信' %> <% end %> </div> ソースコード
試したこと
redirectするpathを変更し、画面遷移を試みましたが変化なしでした。
そもそもDBにメッセージが保存できていないため、paramsでの受け取りに問題があるのでしょうか?
原因だけでもご回答お願いします。
補足情報(FW/ツールのバージョンなど)
[環境]
rails 5.2.3
Ruby 2.5.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/19 09:03
2020/01/19 09:06
2020/01/23 12:51