現在ツイート詳細ページ(show.html.haml)でコメントができます。
ツイートにコメントをしたらコメントする前の状態に戻るようにします。
redirect_back(fallback_location: アクション名)
で直前のページに戻すことができます。
app/controllers/comments_controller.rb
def create
tweet = Tweet.find(params[:tweet_id])
@comment = tweet.comments.build(comment_params)
if @comment.save
redirect_back(fallback_location: tweet_path(tweet))
else
flash[:danger] = "テキストを入力してください"
redirect_back(fallback_location: tweet_path(tweet))
end
end
tweet_path
はshowアクションのprefix
です。
以上!
参考 >https://railsguides.jp/layouts_and_rendering.html
ではまた!