删除功能适用于localhost,但不适用于heroku

时间:2015-11-15 04:59:59

标签: ruby-on-rails ruby-on-rails-4 heroku heroku-postgres

我正在网站上工作并遇到一个问题,点击我的“删除”链接会显示错误页面。在localhost上正常工作 - 无法弄清楚为什么Heroku网站会有所不同。

有没有人知道这是怎么回事?

我的'图片'控制器:

err

我的照片/新观点:

class PicturesController < ApplicationController

  def index
    @pictures = Picture.all
  end

  def new
    @pictures = Picture.all
    @picture = Picture.new 
  end

  def create
    @picture = Picture.new(picture_params)

    if @picture.save
      redirect_to new_picture_path, notice: "You just uploaded a picture!"
    else
      render "new"
    end
  end

  def destroy
    Picture.find(params[:id]).destroy
    redirect_to new_picture_path, notice: "You just deleted a picture!"
  end

...
end

<h1>Upload a new picture</h1>
<br>
<div class="well">
<%= form_for @picture, :html => {:multipart => true} do |f| %>
 <%= f.file_field :attachment %>
 <%= f.submit "Upload", class: "btn btn-default" %>
<% end %>

以下是我尝试删除图片时的heroku日志(从导航到新图片页面开始(同一视图中的新功能和编辑功能):

2015-11-15T16:13:49.189857 + 00:00 heroku [router]:at = info method = GET path =“/ pictures / new”host = designstatements.herokuapp.com request_id = ccb67000-b99f-4579- a664-097247d97414 fwd =“73.238.59.224”dyno = web.1 connect = 1ms service = 46ms status = 200 bytes = 9770

2015-11-15T16:13:49.396294 + 00:00 heroku [router]:at = info method = GET path =“/ pictures / animate.min.css”host = designstatements.herokuapp.com request_id = fb87e1bd- b5cc-4f9f-9934-6c4076beff41 fwd =“73.238.59.224”dyno = web.1 connect = 1ms service = 6ms status = 404 bytes = 1829

2015-11-15T16:13:49.478789 + 00:00 heroku [router]:at = info method = GET path =“/ pictures / js / bootstrap.min.js”host = designstatements.herokuapp.com request_id = 2b36f60f-0e9a-498f-b210-74350c910540 fwd =“73.238.59.224”dyno = web.1 connect = 1ms service = 8ms status = 404 bytes = 1829

2015-11-15T16:13:53.652050 + 00:00 heroku [router]:at = info method = GET path =“/ pictures / 40”host = designstatements.herokuapp.com request_id = 5dbb3c14-fab5-4525- a682-2d037b78dd4a fwd =“73.238.59.224”dyno = web.1 connect = 1ms service = 10ms status = 500 bytes = 1754

1 个答案:

答案 0 :(得分:0)

如您所见,无法找到您的资产(您的日志指出/pictures/js/bootstrap.min.js有404错误。

Rails使用jquery-ujs(一个Javascript库)来模拟DELETE请求,因为浏览器只能执行GETPOSTjquery-ujs会将您已将method: :delete设置为POST请求的常规链接转为_method个参数delete设置为DELETE的请求。这告诉Rails将此请求视为jquery-ujs - 请求。

现在,如果无法加载您的资源,则jquery-ujs也不会加载。如果缺少DELETE,则无法修改您的链接,浏览器会发送GET请求而不是假 config.assets.compile = false 次请求。

要解决此问题,请尝试设置

config/environments/production.rb

DELETE中。这使Heroku服务于您的资产。也许您还必须更改其他设置(尤其是您的资产路径)。但是只要加载了JS和CSS文件,import numpy as np from matplotlib import pyplot as plt import time import matplotlib.widgets as widgets import threading #this is new fig, ax = plt.subplots() # it is not always column 0 and 1 sctPlot = ax.scatter([-0.3,0,0.3], [0.3,0.3,0.3], c="blue", picker = 2, s=[50]*3) fig.subplots_adjust(bottom=0.3, left=0.1) plt.grid(False) plt.axis([-0.6, 0.6, -0.6, 0.6]) loopBool = True def closeLooping(event): global loopBool loopBool = False def looping(event): global loopBool while (loopBool == True): print "Still Looping!" time.sleep(1) print "Stop!!" def looping_pre(event): #this is new thread=threading.Thread(target=looping,args=(event,)) #thread.daemon=True #might or might not be needed thread.start() axCloseButton = plt.axes([0.1, 0.15, 0.2, 0.06]) bClose = widgets.Button(axCloseButton, "Close", hovercolor = '0.975') bClose.on_clicked(closeLooping) plt.show() #this is new fig.canvas.mpl_connect('pick_event', looping_pre) #this is changed 链接就可以正常工作。

相关问题