Heroku上的Rails应用程序不会破坏元素

时间:2014-07-01 15:28:04

标签: ruby-on-rails ruby heroku deployment

我按照rails入门指南创建了一个简单的blog application。我在Heroku上部署了我的应用程序,除了销毁操作外,一切正常。我无法删除任何与他们相关的文章或评论。当我尝试删除文章时,我会被重定向到文章本身,当我尝试删除特定评论时,“您正在寻找的页面不存在。您可能输错了地址或页面可能已移动。”消息显示出来。

我的应用程序在本地完美运行(所有操作都按预期工作)所以我对这个问题感到有些困惑。 我已经在this问题上尝试了这些建议,但问题仍然存在。

索引视图(列出文章看起来像这样)

<h1>Listing articles</h1>
 <%= link_to 'New article', new_article_path %>
<table>
  <tr>
    <th>Title</th>
    <th>Text</th>
  </tr>

  <% @articles.each do |article| %>
    <tr>
      <td><%= article.title %></td>
      <td><%= article.text %></td>
      <td><%= link_to 'Show', article_path(article) %></td>
      <td><%= link_to 'Edit', edit_article_path(article) %></td>
      <td><%= link_to 'Destroy', article_path(article),
                    method: :delete, data: { confirm: 'Are you sure?' } %></td>
    </tr>
  <% end %>
</table>

评论视图如下:

<p>
  <strong>Commenter:</strong>
  <%= comment.commenter %>
</p>

<p>
  <strong>Comment:</strong>
  <%= comment.body %>
</p>
<p>
  <%= link_to 'Destroy Comment', [comment.article, comment],
               method: :delete,
               data: { confirm: 'Are you sure?' } %>
</p>

物品管理员:

class ArticlesController < ApplicationController
  http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show]

  def new
    @article = Article.new
  end

  def create
    @article = Article.new(article_params)

    if @article.save
      redirect_to @article
    else
      render 'new'
    end


  end

  def show
    @article = Article.find(params[:id])
  end


  def index
    @articles = Article.all
  end

  def edit
  @article = Article.find(params[:id])
  end

  def update
    @article = Article.find(params[:id])

    if @article.update(article_params)
      redirect_to @article
    else
      render 'edit'
    end
  end

  def destroy
    @article = Article.find(params[:id])
    @article.destroy

    redirect_to articles_path
  end

  private
  def article_params
    params.require(:article).permit(:title, :text)
  end
end

评论控制器

class CommentsController < ApplicationController
  http_basic_authenticate_with name: "dhh", password: "secret", only: :destroy

  def create
    @article = Article.find(params[:article_id])
    @comment = @article.comments.create(comment_params)
    redirect_to article_path(@article)
  end

  def destroy
    @article = Article.find(params[:article_id])
    @comment = @article.comments.find(params[:id])
    @comment.destroy
    redirect_to article_path(@article)
  end

  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end

end

在我尝试删除文章后,这是“heroku日志”的输出:

2014-07-01T16:49:05.502366+00:00 heroku[router]: at=info method=GET path="/assets/application-5f479ef43502f4271b7b26e7b1d2871e.js" host=eduardo-blog.herokuapp.com request_id=6289876a-1b06-46e7-9929-1a6731eb50d0 fwd="70.53.67.136" dyno=web.1 connect=1ms service=12762ms status=304 bytes=232
2014-07-01T16:49:15.749410+00:00 heroku[router]: at=info method=GET path="/articles" host=eduardo-blog.herokuapp.com request_id=4df2c6a4-6e1a-4602-a97b-e16038acd98a fwd="70.53.67.136" dyno=web.1 connect=3ms service=143ms status=304 bytes=727
2014-07-01T16:49:15.858590+00:00 heroku[router]: at=info method=GET path="/assets/application-778f77f22524bf46ac53b87d2f19943a.css" host=eduardo-blog.herokuapp.com request_id=75761c13-d9cc-41e0-aeb9-764f9619e897 fwd="70.53.67.136" dyno=web.1 connect=4ms service=10ms status=304 bytes=231
2014-07-01T16:49:15.875220+00:00 heroku[router]: at=info method=GET path="/assets/application-5f479ef43502f4271b7b26e7b1d2871e.js" host=eduardo-blog.herokuapp.com request_id=13f6c4c3-8cec-45ef-af36-d55186b35b71 fwd="70.53.67.136" dyno=web.1 connect=3ms service=14ms status=304 bytes=231
2014-07-01T16:49:19.133248+00:00 heroku[router]: at=info method=GET path="/articles/2" host=eduardo-blog.herokuapp.com request_id=1ba4e1ca-70d3-42c3-bd03-105eaa6a4289 fwd="70.53.67.136" dyno=web.1 connect=1ms service=304ms status=304 bytes=727
2014-07-01T16:49:19.219454+00:00 heroku[router]: at=info method=GET path="/assets/application-778f77f22524bf46ac53b87d2f19943a.css" host=eduardo-blog.herokuapp.com request_id=314ae6a5-7cef-408d-8fe4-4e7c25abaf70 fwd="70.53.67.136" dyno=web.1 connect=1ms service=7ms status=304 bytes=231
2014-07-01T16:49:19.242850+00:00 heroku[router]: at=info method=GET path="/assets/application-5f479ef43502f4271b7b26e7b1d2871e.js" host=eduardo-blog.herokuapp.com request_id=cdaffa86-b9a7-45ea-93ff-3c31a4e88f60 fwd="70.53.67.136" dyno=web.1 connect=3ms service=10ms status=304 bytes=231
eduardo@WebDisaster:~/Desktop/rails_projects/blog$

在尝试删除评论后也是如此:

2014-07-01T16:49:05.502366+00:00 heroku[router]: at=info method=GET path="/assets/application-5f479ef43502f4271b7b26e7b1d2871e.js" host=eduardo-blog.herokuapp.com request_id=6289876a-1b06-46e7-9929-1a6731eb50d0 fwd="70.53.67.136" dyno=web.1 connect=1ms service=12762ms status=304 bytes=232
2014-07-01T16:49:15.749410+00:00 heroku[router]: at=info method=GET path="/articles" host=eduardo-blog.herokuapp.com request_id=4df2c6a4-6e1a-4602-a97b-e16038acd98a fwd="70.53.67.136" dyno=web.1 connect=3ms service=143ms status=304 bytes=727
2014-07-01T16:49:15.858590+00:00 heroku[router]: at=info method=GET path="/assets/application-778f77f22524bf46ac53b87d2f19943a.css" host=eduardo-blog.herokuapp.com request_id=75761c13-d9cc-41e0-aeb9-764f9619e897 fwd="70.53.67.136" dyno=web.1 connect=4ms service=10ms status=304 bytes=231
2014-07-01T16:49:15.875220+00:00 heroku[router]: at=info method=GET path="/assets/application-5f479ef43502f4271b7b26e7b1d2871e.js" host=eduardo-blog.herokuapp.com request_id=13f6c4c3-8cec-45ef-af36-d55186b35b71 fwd="70.53.67.136" dyno=web.1 connect=3ms service=14ms status=304 bytes=231
2014-07-01T16:49:19.133248+00:00 heroku[router]: at=info method=GET path="/articles/2" host=eduardo-blog.herokuapp.com request_id=1ba4e1ca-70d3-42c3-bd03-105eaa6a4289 fwd="70.53.67.136" dyno=web.1 connect=1ms service=304ms status=304 bytes=727
2014-07-01T16:49:19.219454+00:00 heroku[router]: at=info method=GET path="/assets/application-778f77f22524bf46ac53b87d2f19943a.css" host=eduardo-blog.herokuapp.com request_id=314ae6a5-7cef-408d-8fe4-4e7c25abaf70 fwd="70.53.67.136" dyno=web.1 connect=1ms service=7ms status=304 bytes=231
2014-07-01T16:49:19.242850+00:00 heroku[router]: at=info method=GET path="/assets/application-5f479ef43502f4271b7b26e7b1d2871e.js" host=eduardo-blog.herokuapp.com request_id=cdaffa86-b9a7-45ea-93ff-3c31a4e88f60 fwd="70.53.67.136" dyno=web.1 connect=3ms service=10ms status=304 bytes=231
2014-07-01T16:54:09.802746+00:00 heroku[router]: at=info method=POST path="/articles/2/comments" host=eduardo-blog.herokuapp.com request_id=be8d8432-1cee-48e6-ad43-cbd3c01a9b43 fwd="70.53.67.136" dyno=web.1 connect=3ms service=44ms status=302 bytes=919
2014-07-01T16:54:09.967749+00:00 heroku[router]: at=info method=GET path="/articles/2" host=eduardo-blog.herokuapp.com request_id=0bc8a5c5-0c08-472a-bb68-5a083fcb6212 fwd="70.53.67.136" dyno=web.1 connect=5ms service=97ms status=200 bytes=2417
2014-07-01T16:54:10.113333+00:00 heroku[router]: at=info method=GET path="/assets/application-778f77f22524bf46ac53b87d2f19943a.css" host=eduardo-blog.herokuapp.com request_id=a121ff02-3ec1-4a10-91e5-e74f434adf49 fwd="70.53.67.136" dyno=web.1 connect=2ms service=43ms status=304 bytes=231
2014-07-01T16:54:10.121288+00:00 heroku[router]: at=info method=GET path="/assets/application-5f479ef43502f4271b7b26e7b1d2871e.js" host=eduardo-blog.herokuapp.com request_id=1244e984-9af1-4c0a-80ba-e3d8f00ffbb4 fwd="70.53.67.136" dyno=web.1 connect=2ms service=49ms status=304 bytes=231
2014-07-01T16:54:12.244713+00:00 heroku[router]: at=info method=GET path="/articles/2/comments/4" host=eduardo-blog.herokuapp.com request_id=c0d28ac7-5bca-4703-bd8f-6b9483a969e6 fwd="70.53.67.136" dyno=web.1 connect=3ms service=29ms status=404 bytes=1829

除了404状态之外,我没有真正看到(或理解那个)任何错误的迹象。 再次感谢你们!

0 个答案:

没有答案