在這裏,我遵循Michael Hartl着名的Ruby on Rails教程(Rails 3.2)。 「11.2.5帶有Ajax的工作按鈕」部分適用於本地機器,但在Heroku上不起作用。 當我單擊Follow或Unfollow按鈕時,頁面上的任何內容都不會刷新。雖然我可以看到這些行爲確實是從日誌中調用的。使用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
然後我不得不手動點擊瀏覽器的刷新按鈕(火狐7.0)刷新整個頁面,該按鈕會在結果正確切換。
文件,應用程序/視圖/佈局/ 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>