twitterのような簡易アプリを作っています。
コメント機能の実装したいのですが、ルーティングエラーになります。
routes.rb
Rails.application.routes.draw do resources :tweets do resources :comments, only: [:create] end end
idを持たせたいのでネスト形にしました。
コマンドでrails routesと打ったらこのようになりました。
tweet_comments POST /tweets/:tweet_id/comments(.:format) comments#create
comennts_controller.rbとview/comments/create.html.hamlは作成済みです。
comments_controller.rb
class CommentsController < ApplicationController def create @comment = Comment.find(params[:id]) end end
やりたいURLは「http://localhost:3000/tweets/:tweet_id/comments」
こうなって欲しいですが、これにアクセスするとルーティングエラーになります。
ルーティングはちゃんと設定してあるのに、何故でしょうか?
かなり基礎的な部分ですが、躓いたのでご教授頂けると嬉しいです。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/29 06:46