我對javascript很陌生,我試圖在Rails應用程序中設置輪詢以提供活動模型中活動的簡化提要。我正在密切關注這裏的投票Railscast:http://railscasts.com/episodes/229-polling-for-changes-revised?view=asciicast在Rails應用程序中設置Javascript輪詢
我已經設置了一個非常簡單的測試警報,以在頁面加載時觸發,但是當我加載頁面時警報沒有出現。我希望有人能夠澄清爲什麼它不會出現。
這裏的觀點:
<h4>Activities</h4>
<div class="well col-sm-5 activity_monitor" data-url="<%=activities_path%>">
<% @activities.each do |activity| %>
Student <%= activity.trackable_id %> began a tutoring session at <%=activity.created_at %>
<br>
<% end %>
</div>
這裏是我的簡單的CoffeeScript:
ActivityPoller =
poll: ->
setTimeout @request, 5000
request: ->
$.get($('.activity_monitor').data('url'))
jQuery ->
if $('.activity_monitor').length > 0
ActivityPoller.poll()
這裏的控制器:
class ActivitiesController < ApplicationController
def index
@activities=Activity.all
end
end
這裏的index.js.erb的文件:
alert("This is a test alert");
當我加載頁面,這是我看到的控制檯輸出:
Consider using 'dppx' units, as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. In media query expression: only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 144dpi) activities:1
Uncaught ReferenceError: define is not defined wizard.js?body=1:10(anonymous function) wizard.js?body=1:10
GET http://localhost:8080/assets/jquery.nanoscroller.min.js.map 404 (Not Found) activities:102
'Range.detach' is now a no-op, as per DOM (http://dom.spec.whatwg.org/#dom-range-detach). bootstrap3-wysihtml5.min.js?body=1:56
The "fb-root" div has not been created, auto-creating sdk.js:56