jquery - Rails clock display -


i have application needs display clock on index page. have static controller this:

controllers/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 

and have on views/static/index.html.erb:

<div class="time-container">    <%= render partial: "date" %> </div> 

and partial views/static/_date.html.erb contains var:

  <%=@time%> 

i used js function try update time on assets/javascripts/static.js:

$(document).ready(function () {     setinterval(function () {         $('.time-container').load('/static/get_time');      }, 1000); }); 

my routes.rb this:

rails.application.routes.draw   # details on dsl available within file, see http://guides.rubyonrails.org/routing.html   root "static#index"   resources :static  end 

this way, clock shows when page loads, stays same , not update. missing something?

your routes don't match flow built.

you lucky static/index worked because included within resources statement.

take out the:

resources :static 

and replace with

get 'static/index' 'static/get_time' 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -