前提・実現したいこと
cloud9を使いrailsでアプリケーションを作っていたのですが、コメント機能を非同期で作っていたところ、Template is missingのエラーが発生しました。コードを見直してもおかしなところは見つからず、どこを修正すれば良いか困っています。
発生している問題・エラーメッセージ
該当のソースコード
public/posts/show.html.erb
<div class="comment"> <div class="comment-count"> <%= @post.comments.count %>件コメント </div> <div id="comments_area"> <%= render partial: 'public/comments/index', locals: { comments: @comments,user: @user } %> </div> <% if user_signed_in? %> <div class="comment-create"> <h3 class="text-left">レビューを投稿する</h3> <%= render partial: 'public/comments/form', locals: { comment: @comment, user: @user, post: @post} %> </div> <% end %> </div>
routes.rb
namespace :public, path: "" do get 'users/mypage/:id' => 'users#mypage' resources :users, only: [:edit, :update ,:index , :show] do resources :posts, only: [:index,:create,:show,:edit,:update, :destroy] do delete 'post_item_destroy' post 'post_item_create' resources :post_items, only: [:destroy, :index] resources :likes, only: [:create, :destroy] resources :comments, only: [:create, :destroy] end get 'search_posts', to: 'posts#search' resource :relationships, only: [:create, :destroy] get 'followings' => 'relationships#followings', as: 'followings' get 'followers' => 'relationships#followers', as: 'followers' resource :favorites, only: [:create, :destroy] end resources :messages, only: [:create] resources :rooms, only: [:create,:show, :index] get '/profiles/mypage' => 'profiles#mypage' resources :tags, only: [:show] end devise_for :admins end
comments/_index.html.erb
<div class="container"> <div class="row"> <div class="col"> <div class="comments"> <h6 class="more m-2" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">もっと見る....</h6> <% @comments.first(2).each do |comment| %> <% unless comment.id.nil? %> <div class="comment-container m-2"> <div class="comment-box"> <div class="comment-item d-flex"> <div class="comment-avatar"> <%= attachment_image_tag comment.user, :image, fallback: "no_image.jpg", class:"comment-image", size: "40x40" %> </div> <div class="comment-text mt-3 ml-3"> <p><%= link_to "@#{comment.user.full_name}", public_path(comment.user.id) %></p> </div> <span class="comment-date pull-right"> <p class="mt-3 ml-3"><%= comment.created_at.strftime('%Y/%m/%d %H:%M:%S') %></p> </span> </div> <div class="comment-entry mb-3"> <%= comment.comment_content %> <% if comment.user_id == current_user.id %> <%= link_to public_user_post_comment_path(comment.user.id, comment.post_id, comment.id), method: :delete, remote: true, class: "comment_destroy" do %> <i class="fas fa-trash" style="color: black;"></i> <% end %> <% end %> </div> </div> </div> <% end %> <% end %> <div class="collapse m-2" id="collapseExample"> <% comments.offset(2).each do |comment| %> <% unless comment.id.nil? %> <div class="comment-container m-2"> <div class="comment-box"> <div class="comment-item d-flex"> <div class="comment-avatar"> <div><%= attachment_image_tag comment.user, :image, fallback: "no_image.jpg", class:"comment-image", size: "40x40" %></div> </div> <div class="comment-text mt-3 ml-3"> <p><%= link_to "@#{comment.user.full_name}", public_path(comment.user.id) %></p> </div> <span class="comment-date pull-right mt-3 ml-3"> <%= comment.created_at.strftime('%Y/%m/%d %H:%M:%S') %> </span> </div> <div class="comment-entry mb-4"> <%= comment.comment_content %> <% if comment.user_id == current_user.id %> <%= link_to public_user_post_comment_path(comment.user.id, comment.post_id, comment.id), method: :delete, remote: true, class: "comment_destroy" do %> <i class="fas fa-trash" style="color: black;"></i> <% end %> <% end %> </div> </div> </div> <% end %> <% end %> </div> </div> </div> </div> </div>
index.js.erb
$("#comments_area").html("<%= j(render 'index', { comments: @comment.user.comments }) %>") $("textarea").val('')
_form.html.erb
<%= form_with model: @comment, url: public_user_post_comments_path(@user.id, @post.id, @comment.id),remote: true do |f| %> <%= f.text_area :comment_content, class: "input-mysize" %> <%= f.submit "送信", class: "btn btn-outline-dark comment-submit float-right" %> <% end %>
試したこと
コードを何度も見返してみましたが、どこに原因があるかわかっていない状態です。
お忙しいとは思いますが、回答よろしくお願いいたします
補足情報(FW/ツールのバージョンなど)
cloud9
回答1件
あなたの回答
tips
プレビュー