前提
Rubyでホテル検索サイトを作っている者です。
トラブルが続いたため、最初から作り直すことになりました。
投稿の編集ページに飛ぼうとしたところ、以下のようなエラーメッセージが発生してしまいました。
発生している問題・エラーメッセージ
No template for interactive request HotelsController#edit 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.
該当のソースコード
エラー画面にソースコードが表示されなかったため、editアクションの実装コードを貼ります
1つ目:hotels_controller.rb
def edit @hotel = Hotel.find(params[:id]) end
2つ目:edit.html.erb
<%= form_for @hotel do |f| %> <%= f.label :name %> <%= f.text_field :name, :size => 80 %><br> <%= f.label :price1 %> <%= f.number_field :price1, :size => 60 %><br> <%= f.label :price2 %> <%= f.number_field :price2, :size => 60 %><br> <%= f.label :address %> <%= f.text_area :address, :size =>"50x2" %> <%= f.submit "編集する" %> <% end %>
3つ目:一覧ページに編集ページへのリンクを貼るコード
<h1>Travel</h1> <h3>Hotel一覧</h3> <%= link_to "新規投稿へ", hotels_new_path %> <div class="hotels-container"> <% @hotels.each do |t| %> <div class="hotel"> <%= t.name %> <%= t.price1 %> <%= t.price2 %> <%= t.address %> <%= t.created_at %> <%= link_to "詳細へ", hotel_path(t.id) %> <%= link_to "編集する", edit_hotel_path(t.id) %> </div> <% end %> </div>
4つ目詳細ページに編集ページへのリンクを張るコード
<h1>Travel</h1> <h3>詳細</h3> <div class="hotel"> <p><%= @hotel.name %></p> <p><%= @hotel.price1 %></p> <p><%= @hotel.price2 %></p> <p><%= @hotel.address %></p> <p><%= @hotel.created_at %></p> </div> <%= link_to "編集する", edit_hotel_path(@hotel.id) %> <%= link_to "一覧に戻る", hotels_path %>
試したこと
新規投稿アクションのコードと見比べましたが、間違っている箇所が見つかりません。どうすれば消えてくれるのでしょうか…… どうかお願いいたします
<%= form_for @hotel do |f| %> <div class="field"> <%= f.label :name %> <%= f.text_field :name, :size => 80 %><br> <%= f.label :price1 %> <%= f.number_field :price1, :size => 60 %><br> <%= f.label :price2 %> <%= f.number_field :price2, :size => 60 %><br> <%= f.label :address %> <%= f.text_area :address, :size =>"50x2" %> </div>
補足情報(FW/ツールのバージョンなど)
Rails 6.1.7
Windows11

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/12/08 00:07
2023/01/18 09:27