【问题标题】:rails works locally, but server statut 304 on herokurails 在本地工作,但在 heroku 上服务器 statut 304
【发布时间】:2019-10-16 13:55:30
【问题描述】:

我在 Rails 中通过 ajax 渲染部分内容。在本地工作得很好,但在 heroku 上我得到了 304 并且网页上没有任何反应:http://www.cremers.fr/articles/histoire

我首先像这样渲染所有文章:

all_finance.html.erb

<%= render 'articles' %>

然后在部分_articles.html.erb:

<% @articles.each do |a| %>
    <% if a.categorie == "histoire" %>
        <%= link_to "lire la suite", article_histoire_url(a.id), remote: true %>
    <% elsif a.categorie == "finance"  %>
        <%= link_to "lire la suite", article_finance_url(a.id), remote: true %> 
    <% end %>
<% end %>

article_finance_url 处理操作article#financefinance.js.erbcontains:

document.getElementById('trunc_article_<%= @article.id %>').remove();
document.getElementById('add_article_<%= @article.id %>').innerHTML = '<%= render("contenu") %>';
document.getElementById('add_link_<%= @article.id %>').innerHTML = '<%= link_to image_tag("partage.png", size: "20x20", class: "marge_ht"), article_finance_url(@article.id) %>';

finance.html.erbcontains:

<%= render 'article' %>

在本地运行它可以正常工作。在 heroku 上,服务器响应正确的内容,即 finance.js.erb 使用嵌入的模板正确呈现,但也会给出 304 响应。

【问题讨论】:

  • 状态 304 不是错误,它是一个“未修改”响应,它告诉浏览器使用它请求的任何文件的缓存版本,因此它不必再次发送数据。您的浏览器控制台上显示了一些 javascript 错误,请先修复这些错误。

标签: javascript ruby-on-rails ruby heroku


【解决方案1】:

为了后代:在我的例子中,我省略了 js 文件中的右括号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 2016-11-05
    • 2020-03-16
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多