困っている箇所
掲載物に応募ボタンを設置し、応募ボタンを押すと、掲載者と応募者のDMが作成され、
やり取りできる機能を追加したのですが、応募ボタンを押した後にエラーが発生しました。
調べてみると、roomのhtmlページがないと言っているのですが、しっかりとrooms/showページは作成してあります。
またRooms_controllerのshowに関してもしっかりと機能を書いていると思うのですが、どこがおかしいかわかりません。
見て頂けないでしょうか?
エラーメッセージ
No template for interactive request RoomsController#show is missing a template for request formats: text/html NOTE! Unless told otherwise, Rails expects an action to render a template with the same name, contained in a folder named after its controller. If this controller is an API responding with 204 (No Content), which does not require a template, then this error will occur when trying to access it via browser, since we expect an HTML template to be rendered for such requests. If that's the case, carry on.
views/rooms/show.html.erb
<div class="left-button"> <%= link_to "ホームに戻る", "/",class:"edit-link" %> </div> <h4 class="rooms-title">気になる同士</h4> <% @entries.each do |e| %> <div class="user-name"> <strong> <%= image_tag e.user.avatar, class:"user-image" %> <a class="rooms-user-link" href="/users/<%= e.user.id %>"> <%= e.user.name %>さん </a> </strong> </div> <% end %> <hr> <div class="chats"> <div class="chat"> <% if @messages.present? %> <% @messages.each do |m| %> <div class="chat-box"> <div class="chat-face"> <%= image_tag m.user.avatar, class:"user-image" %> </div> <div class="chat-hukidashi"> <strong><%= m.content %></strong> <br> <%= m.created_at.strftime("%Y-%m-%d %H:%M")%> </div> </div> <% end %> <% end %> </div> <div class="posts"> <%= form_for @message do |f| %> <%= f.text_field :content, placeholder: "メッセージを入力して下さい" , size: 70, class:"form-text-field" %> <%= f.hidden_field :room_id, value: @room.id %> <%= f.submit "投稿",class: 'form-submit'%> <% end %> </div> </div>
rooms_controller
class RoomsController < ApplicationController before_action :authenticate_user! def create @room = Room.create @entry1 = Entry.create(room_id: @room.id, user_id: current_user.id) @entry2 = Entry.create(params.require(:entry).permit(:user_id, :room_id).merge(room_id: @room.id)) redirect_to "/rooms/#{@room.id}" end def show @room = Room.find(params[:id]) if Entry.where(user_id: current_user.id,room_id: @room.id).present? @messages = @room.messages @message = Message.new @entries = @room.entries else redirect_back(fallback_location: root_path) end end end
参考サイトは下記です
https://qiita.com/bindingpry/items/6790c91f374acc25bea2
https://qiita.com/nojinoji/items/2b3f8309a31cc6d88d03
https://qiita.com/aaaasahi_17/items/9e7f344488c720aaf116
回答1件
あなたの回答
tips
プレビュー