掲示版のコメントフォームを作っています。
コメントを投稿しても掲示板に反映されず、元のページに戻ってしまいます。
以下loggerを使ったログになります
リンク内容
コメントフォーム
<%= form_with model: [@post,@comment] do |f| %>
<%= f.label :content, 'コメント内容' %>
<%= f.text_area :content %>
<br>
<%= f.submit 'コメントする' %>
<% end %>
commente controller ```ここに言語を入力 class CommentsController < ApplicationController def create @comment = Comment.new logger.debug @comment.errors.inspect if @comment.save redirect_back(fallback_location: root_path) else @comments = Comment.all redirect_back(fallback_location: root_path) end end end
ルーティング
resources :users, only: [:index, :show, :create] resources :posts do post "comments", to: "comments#create" end
commentテーブル
Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+----------------+ | id | bigint(20) | NO | PRI | NULL | auto_increment | | content | varchar(255) | YES | | NULL | | | user_id | bigint(20) | YES | MUL | NULL | | | post_id | bigint(20) | YES | MUL | NULL | | | created_at | datetime | NO | | NULL | | | updated_at | datetime | NO | | NULL | | +------------+--------------+------+-----+---------+----------------+
ログ(コメント投稿から)
I, [2021-09-06T22:54:39.944495 #3215] INFO -- : Started GET "/posts/11" for 118.103.63.149 at 2021-09-06 22:54:39 +0000 I, [2021-09-06T22:54:39.945135 #3215] INFO -- : Cannot render console from 118.103.63.149! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 I, [2021-09-06T22:54:39.946224 #3215] INFO -- : Processing by PostsController#show as HTML I, [2021-09-06T22:54:39.946367 #3215] INFO -- : Parameters: {"id"=>"11"} D, [2021-09-06T22:54:39.947606 #3215] DEBUG -- : Post Load (0.4ms) SELECT `posts`.* FROM `posts` WHERE `posts`.`id` = 11 LIMIT 1 D, [2021-09-06T22:54:39.947835 #3215] DEBUG -- : ↳ app/controllers/posts_controller.rb:11 I, [2021-09-06T22:54:39.949465 #3215] INFO -- : Rendering posts/show.html.erb within layouts/application D, [2021-09-06T22:54:39.951562 #3215] DEBUG -- : User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 27 LIMIT 1 D, [2021-09-06T22:54:39.952374 #3215] DEBUG -- : ↳ app/views/posts/show.html.erb:2 D, [2021-09-06T22:54:39.953760 #3215] DEBUG -- : Comment Load (0.2ms) SELECT `comments`.* FROM `comments` WHERE `comments`.`post_id` = 11 D, [2021-09-06T22:54:39.954545 #3215] DEBUG -- : ↳ app/views/posts/show.html.erb:6 I, [2021-09-06T22:54:39.955987 #3215] INFO -- : Rendered posts/show.html.erb within layouts/application (5.6ms) I, [2021-09-06T22:54:39.961509 #3215] INFO -- : Completed 200 OK in 15ms (Views: 12.5ms | ActiveRecord: 0.8ms) I, [2021-09-06T22:55:03.655420 #3215] INFO -- : Started POST "/posts/11/comments" for 118.103.63.149 at 2021-09-06 22:55:03 +0000 I, [2021-09-06T22:55:03.655996 #3215] INFO -- : Cannot render console from 118.103.63.149! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 I, [2021-09-06T22:55:03.657532 #3215] INFO -- : Processing by CommentsController#create as HTML I, [2021-09-06T22:55:03.657692 #3215] INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"7vdISLkJESCXfdUUXmfhhBJmLwpU0pH7yrvWChoJpEKaoTCzKBLV413ohLFVsNvS4RqwVMfNDvE8zOP2Si85+w==", "comment"=>{"content"=>"いいところ"}, "commit"=>"コメントする", "post_id"=>"11"} D, [2021-09-06T22:55:03.658725 #3215] DEBUG -- : #<ActiveModel::Errors:0x00007f2c98045d50 @base=#<Comment id: nil, content: nil, user_id: nil, post_id: nil, created_at: nil, updated_at: nil>, @messages={}, @details={}> D, [2021-09-06T22:55:03.659694 #3215] DEBUG -- : (0.1ms) BEGIN D, [2021-09-06T22:55:03.660342 #3215] DEBUG -- : ↳ app/controllers/comments_controller.rb:5 D, [2021-09-06T22:55:03.662682 #3215] DEBUG -- : (0.1ms) ROLLBACK D, [2021-09-06T22:55:03.663351 #3215] DEBUG -- : ↳ app/controllers/comments_controller.rb:5 I, [2021-09-06T22:55:03.664243 #3215] INFO -- : Redirected to https://ac7c34ad0f0d4d6c88e67a1fd746ee4a.vfs.cloud9.ap-northeast-1.amazonaws.com/posts/11 I, [2021-09-06T22:55:03.664980 #3215] INFO -- : Completed 302 Found in 7ms (ActiveRecord: 0.3ms)
見てくださりありがとうございます。
私一人の力では全く解決できませんでした。どうか少しでも力を貸してくださると幸いですよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー