0
나는 색인 페이지에 시계를 표시해야하는 응용 프로그램이 있습니다. 그래서 나는이 같은 정적 컨트롤러가 :레일 시계 디스플레이
컨트롤러/static_controller.rb :
class StaticController < ApplicationController
def index
@time = Time.now.strftime("%H:%M:%S ")
end
def get_time
@time = Time.now.strftime("%H:%M:%S ")
render partial: "date"
end
end
내가보기에/정적/index.html.erb을이 있습니다
<div class="time-container">
<%= render partial: "date" %>
</div>
및 var :
<%[email protected]%>
내가 사용하는 부분 뷰/static/_date.html.erb 이 자산/자바 스크립트/static.js에 시간을 업데이트하려고하는 기능을 JS :
$(document).ready(function() {
setInterval(function() {
$('.time-container').load('/static/get_time');
}, 1000);
});
내 routes.rb이 있습니다
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root "static#index"
resources :static
end
이 방법은, 시계는 페이지가로드 될 때를 보여줍니다 하지만 항상 동일하게 유지되며 업데이트되지 않습니다. 내가 놓친 게 있니?
로 교체 :
은을 가지고? –
예 : http : // localhost : 3000/static/get_time 404 (찾을 수 없음) –
경로 구성이 누락 되었습니까? –