destroyアクションを実行すると、このようなエラーが表示されます。
URL:http://localhost:3000/listings/テスト
View
<% @alllistings.all.order(created_at: :desc).each do |listing| %> <tbody> <tr> <th scope="row"> <%= link_to listing_path(listing) do %> <span class="listing-title"><%= listing.listing_title %></span> <% end %> </th> <td> <%= listing.listing_category %> </td> <td> <% if listing.active == true %> 公開済み <% else %> 非公開 <% end %> </td> <td> <%= listing.created_at.strftime("%Y年%m月%d日") %> </td> <td> <%= link_to "編集", edit_listing_path(listing) %> </td> <td> <%= link_to "削除",[listing],method: :delete, data: {confirm: "削除してもよろしいでしょうか?"} if current_user = listing.user %> </td> </tr> </tbody> <% end %>
Controller
class ListingsController < ApplicationController before_action :set_listing, only: [:destroy] def index @alllistings = current_user.listings end def destroy @listing.destroy return reedirect_to listings_path, notice: "削除しました", :status => :moved_permanently end private def set_listing @listing = Listing.friendly.find(params[:id]) end end
Model
class Listing < ApplicationRecord validates :listing_title, presence: true include FriendlyId friendly_id :listing_title def should_generate_new_friendly_id? listing_title_changed? end end
rails 5
gem 'friendly_id'を活用しております。
slugも導入しました。
ご回答の方よろしくお願いします。
あなたの回答
tips
プレビュー