破坏功能在RoR中不起作用

时间:2016-09-21 23:38:44

标签: ruby-on-rails ruby

class BooksController < ApplicationController
  before_action :set_book, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user!, except: [:index, :show]



  def show
    @reviews = Review.where(book_id: @book.id).order("created_at DESC")

      if @reviews.blank?
        @avg_review = 0
      else
        @avg_review = @reviews.average(:rating).round(2)
    end
  end


  def destroy
    @book.destroy
    respond_to do |format|
      format.html { redirect_to books_url, notice: 'Book was successfully destroyed.' }
      format.json { head :no_content }
    end
  end



  private
    def set_book
      @book = Book.find(params[:id])
    end

    def book_params
      params.require(:book).permit(:title, :author, :language, :year, :description, :total_pages, :rating, :image)
    end

  end

这是我的书籍控制器和我的&#34;删除&#34;在show文件中如下。

<%= link_to 'Delete', book, 
    data: { confirm: 'Are you sure?' }, method: :delete %>

我正在获取链接,但它无法正常工作。我的代码有什么问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

确保将//= require jquery_ujs放入 assets/javascripts/application.js