“毁灭”无法在生产中使用 - Rails App

时间:2016-10-03 18:41:12

标签: ruby-on-rails heroku

我对Rails相当新。我正在尝试将书评应用程序投入生产。我松散地将它建立在在线教程上。我有一个按钮,据说将删除我的应用程序中的“预订”条目。我在书的展示页面上有一个删除按钮。但是,当我单击以删除书籍条目时,它会重定向到该书籍显示页面而不执行任何操作。该按钮在生产中完美运行。

我已经预先编译了我的资产。所以我对发生了什么感到困惑。

这是Heroku日志:

2016-10-03T18:28:09.421132+00:00 heroku[router]: at=info method=GET      path="/books/3" host=seaboltapplication.herokuapp.com request_id=9c80f545-4de0-4330-9771-b97f47c49d06 fwd="69.181.73.43" dyno=web.1 connect=1ms service=106ms status=200 bytes=3350
2016-10-03T18:28:09.295950+00:00 app[web.1]: I, [2016-10-03T18:28:09.295839 #3]  INFO -- : [9c80f545-4de0-4330-9771-b97f47c49d06] Started GET "/books/3" for 69.181.73.43 at 2016-10-03 18:28:09 +0000
2016-10-03T18:28:09.297370+00:00 app[web.1]: I, [2016-10-03T18:28:09.297254 #3]  INFO -- : [9c80f545-4de0-4330-9771-b97f47c49d06] Processing by BooksController#show as HTML
2016-10-03T18:28:09.297509+00:00 app[web.1]: I, [2016-10-03T18:28:09.297433 #3]  INFO -- : [9c80f545-4de0-4330-9771-b97f47c49d06]   Parameters: {"id"=>"3"}
2016-10-03T18:28:09.318597+00:00 app[web.1]: D, [2016-10-03T18:28:09.318473 #3] DEBUG -- : [9c80f545-4de0-4330-9771-b97f47c49d06]   User Load (6.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
 2016-10-03T18:28:09.328080+00:00 app[web.1]: D, [2016-10-03T18:28:09.327992 #3] DEBUG -- : [9c80f545-4de0-4330-9771-b97f47c49d06]   Book Load (3.2ms)  SELECT  "books".* FROM "books" WHERE "books"."id" = $1 LIMIT $2  [["id", 3], ["LIMIT", 1]]
  2016-10-03T18:28:09.355978+00:00 app[web.1]: D, [2016-10-03T18:28:09.355856 #3] DEBUG -- : [9c80f545-4de0-4330-9771-b97f47c49d06]   Review Load (24.8ms)  SELECT "reviews".* FROM "reviews" WHERE "reviews"."book_id" = $1  [["book_id", 3]]
 2016-10-03T18:28:09.357259+00:00 app[web.1]: I, [2016-10-03T18:28:09.357181 #3]  INFO -- : [9c80f545-4de0-4330-9771-b97f47c49d06]   Rendering books/show.html.erb within layouts/application
 2016-10-03T18:28:09.384356+00:00 app[web.1]: D, [2016-10-03T18:28:09.384194 #3] DEBUG -- : [9c80f545-4de0-4330-9771-b97f47c49d06]    (15.7ms)  SELECT COUNT(*) FROM "reviews" WHERE "reviews"."book_id" = $1  [["book_id", 3]]
2016-10-03T18:28:09.385772+00:00 app[web.1]: I, [2016-10-03T18:28:09.385704 #3]  INFO -- : [9c80f545-4de0-4330-9771-b97f47c49d06]   Rendered collection of templates [0 times] (0.0ms)
2016-10-03T18:28:09.387771+00:00 app[web.1]: I, [2016-10-03T18:28:09.387705 #3]  INFO -- : [9c80f545-4de0-4330-9771-b97f47c49d06]   Rendered books/show.html.erb within layouts/application (28.5ms)
 2016-10-03T18:28:09.395073+00:00 app[web.1]: I, [2016-10-03T18:28:09.394993 #3]  INFO -- : [9c80f545-4de0-4330-9771-b97f47c49d06] Completed 200 OK in 97ms (Views: 22.4ms | ActiveRecord: 50.1ms)
2016-10-03T18:28:09.513597+00:00 app[web.1]: I, [2016-10-03T18:28:09.513474 #3]  INFO -- : [85138d87-8923-459e-b5c4-0c8c8458fbf8] Started GET "/assets/application.scss" for 69.181.73.43 at 2016-10-03 18:28:09 +0000
2016-10-03T18:28:09.539647+00:00 heroku[router]: at=info method=GET path="/assets/application.scss" host=seaboltapplication.herokuapp.com request_id=85138d87-8923-459e-b5c4-0c8c8458fbf8 fwd="69.181.73.43" dyno=web.1 connect=1ms service=9ms status=304 bytes=258
2016-10-03T18:28:09.636363+00:00 heroku[router]: at=info method=GET path="/assets/application-8e81f96a4be820b7a898f27d43882ce589b4df24917971fd73bf945e1a4700db.js" host=seaboltapplication.herokuapp.com request_id=370fb212-f097-4afd-9651-0b5584845e17 fwd="69.181.73.43" dyno=web.1 connect=0ms service=1ms status=304 bytes=48
2016-10-03T18:28:09.752359+00:00 heroku[router]: at=info method=GET path="/assets/mobile.scss" host=seaboltapplication.herokuapp.com request_id=69751179-3193-4419-8ba8-a21bea0e01ea fwd="69.181.73.43" dyno=web.1 connect=0ms service=9ms status=304 bytes=258
 2016-10-03T18:28:09.737788+00:00 app[web.1]: I, [2016-10-03T18:28:09.737698 #3]  INFO -- : [69751179-3193-4419-8ba8-a21bea0e01ea] Started GET "/assets/mobile.scss" for 69.181.73.43 at 2016-10-03 18:28:09 +0000

Johns-MacBook-Pro:BookApp johnseabolt $

这是我的书籍控制器:     class BooksController< ApplicationController的     before_action:authenticate_user!,only:[:new,:edit,:index,:show]

def index
    @books = Book.all
end

def new
    @book = current_user.books.new
end

def create 
    @book = current_user.books.build(book_params)
    if @book.save 
        redirect_to books_path
    else
        render 'new'
    end
end

def show
    @book = Book.find(params[:id])
    if @book.reviews.blank? 
        @average_review = 0
    else 
        @average_review = @book.reviews.average(:rating).round(2)
    end
end 

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

def update
@book = Book.find(params[:id])
if @book.update(book_params)
    redirect_to book_path(@book)
else
    render "edit"
end
end 


def destroy
    @book = Book.find(params[:id])
    @book.destroy
    if @book.destroy 
        redirect_to books_path
    else
        render 'show_books_path'
    end
end

private
    def book_params
        params.require(:book).permit(:description, :author, :category_id, :book_img, :title)
    end
end

以下是本书展示页面的相关部分:

    

    <div class="inner_left">
    <%= image_tag @book.book_img.url, :class => "book_show" %>  

        <div class="buttons">

            <% if user_signed_in? then %>
                <% if current_user.id = @book.user_id %>
                    <%= link_to "Edit", edit_book_path, :class => "btn_left" %>
                    <%= link_to "Delete", book_path(@book), method: :delete, :class => "btn_right", data: {confirm: "Are you sure?"} %>
                 <% end %>  
             <% end %>
             <br />
             <%= link_to "Back", root_path, :class => "btn" %>
             <br />

             <%= link_to "Add Review", new_book_review_path(@book) , :class => "btn_submit" %>
        </div>
    </div>

以下是我的config / enivornments / prodection.rb文件的相关部分:

 config.assets.compile = true

3 个答案:

答案 0 :(得分:0)

method: :destroy更改为method: :delete

而不是

<%= link_to "Delete", book_path(@book), method: :destroy, :class => "btn_right", data: {confirm: "Are you sure?"} %>

使用

<%= link_to "Delete", book_path(@book), method: :delete, :class => "btn_right", data: {confirm: "Are you sure?"} %>

如果这仍然无效,则表示您未加载JQuery-ujs。确保在application.js

中有以下内容
//= require jquery
//= require jquery_ujs

答案 1 :(得分:0)

在BooksController类中,尝试替换

only: [:new, :edit, :index, :show]

only: [:new, :edit, :index, :show, :destroy] 

答案 2 :(得分:0)

检查您的application.js(app / assets /)并确保按照确切的顺序

//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require_tree .

没有必要提升一个。