質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

602閲覧

renderメソッドをうまく使えない テンプレートエラー

shinnosukepro

総合スコア4

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2021/01/28 04:12

前提・実現したいこと

contollorのrenderメソッドを使って showページ飛ばしたいのですが、できなくて困っています

発生している問題・エラーメッセージ

Template is missing
Missing template comments/show, application/show with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in: * "/Users/takayamashinnosuke/projects/protospace-33990/app/views" * "/Users/takayamashinnosuke/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/devise-4.7.3/app/views" * "/Users/takayamashinnosuke/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/actiontext-6.0.3.4/app/views" * "/Users/takayamashinnosuke/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/actionmailbox-6.0.3.4/app/views"

該当のソースコード

comments_controllrer.rb

class CommentsController < ApplicationController
def create
@comment = Comment.create(comment_params)
if @comment.save
redirect_to root_path
else
render :show
end
end

private
def comment_params
params.require(:comment).permit(:text).merge(user_id: current_user.id, prototype_id: params[:prototype_id])
end
end

show.html.erb

<main class="main"> <div class="inner"> <div class="prototype__wrapper"> <p class="prototype__hedding"> <%= @prototype.content %> </p> <%= link_to "by #{@prototype.user.name}", root_path, class: :prototype__user %> <% if user_signed_in? && current_user.id == @prototype.user_id %> <div class= "prototype__manage"> <%= link_to "編集する", edit_prototype_path(@prototype.id), class: :prototype__btn %> <%= link_to "削除する", prototype_path(@prototype), method: :delete, class: :prototype__btn %> </div> <% end %> <%# // プロトタイプの投稿者とログインしているユーザーが同じであれば上記を表示する %> <div class="prototype__image"> <%= image_tag @prototype.image %> </div> <div class="prototype__body"> <div class="prototype__detail"> <p class="detail__title">キャッチコピー</p> <p class="detail__message"> <%= @prototype.catch_copy %> </p> </div> <div class="prototype__detail"> <p class="detail__title">コンセプト</p> <p class="detail__message"> <%= @prototype.concept %> </p> </div> </div> <div class="prototype__comments"> <%# ログインしているユーザーには以下のコメント投稿フォームを表示する %> <%= form_with model: [@prototype, @comment], local: true do |f|%> <div class="field"> <%= f.label :text, "コメント" %><br /> <%= f.text_field :text %> </div> <div class="actions"> <%= f.submit "送信する", class: :form__btn %> </div> <% end %> <%# // ログインしているユーザーには上記を表示する %> <ul class="comments_lists"> <%# 投稿に紐づくコメントを一覧する処理を記述する %> <li class="comments_list"> <%= @comments.each do |comment| %> <%= link_to comment.user.id, root_path, class: :comment_user %> <% end %> </li> <%#// 投稿に紐づくコメントを一覧する処理を記述する %> </ul> </div> </div> </div> </main> ### 試したこと

routesにshowアクションを追加したが変化無し

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

winterboum

2021/01/28 07:42

1. 読みにくいので <code>で書いてください。 2. 念の為、show.html.erb の置いてあるdirを appから書いてください
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問