在这里,我正在关注 Michael Hartl 著名的 Ruby on Rails 教程(Rails 3.2)。“11.2.5 使用 Ajax 的工作跟随按钮”部分适用于本地计算机,但不适用于 Heroku。当我单击“关注”或“取消关注”按钮时,页面上的任何内容都不会刷新。虽然我可以看到该操作确实是从日志中调用的。
2012-02-22T04:05:17+00:00 app[web.1]: Started POST "/relationships" for 67.188.133.121 at 2012-02-22 04:05:17 +0000
2012-02-22T04:05:17+00:00 app[web.1]: Processing by RelationshipsController#create as JS
2012-02-22T04:05:17+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"nsYrHM0aLlEGoI19Zv8hImEmbfWPZ+gSy5xmgAV+V60=", "relationship"=>{"followed_id"=>"15"}, "commit"=>"Follow"}
2012-02-22T04:05:17+00:00 app[web.1]: Redirected to https://etl-rails32-tut-sample-app.herokuapp.com/users/15
2012-02-22T04:05:17+00:00 app[web.1]: cache: [POST /relationships] invalidate, pass
2012-02-22T04:05:17+00:00 app[web.1]: Completed 302 Found in 66ms (ActiveRecord: 61.2ms)
2012-02-22T04:05:17+00:00 heroku[router]: POST etl-rails32-tut-sample-app.herokuapp.com/relationships dyno=web.1 queue=0 wait=0ms service=75ms status=302 bytes=123
然后我必须手动单击浏览器(FireFox 7.0)的刷新按钮来刷新整个页面,并且该按钮会在结果中正确切换。
文件 app/views/layouts/application.html.erb 如下:
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= render 'layouts/stylesheets' %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="container">
<%= render 'layouts/header' %>
<section class="round">
<% flash.each do |key, value| %>
<%= content_tag(:div, value, class: "flash #{key}") %>
<% end %>
<%= yield %>
</section>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>