Using js.rjs to render inline content
Asked Answered
A

1

0

I am trying to improve my knowledge of Rails. I was trying to use js.rjs in a simple code. Here's the view:

<div style="background: #000080; font-weight: bold; margin-left: 30px"><p>This should     Remain Same</p></div>
    <div id="noid">


    <%=link_to 'Click',:action=>:say_when , :remote => true %>  

      and I will look it up.
    </div>

And here's the controller:

class DemoController < ApplicationController

    def say_when

      respond_to do |format|
        format.js
      end    

    end

end

And I have views/Say_when.js.rjs as follows:

page.replace_html('noid', render(:text=>"OK"))

But when the "click" link is clicked, nothing happens. What am I doing wrong?

Ataxia answered 15/3, 2011 at 2:1 Comment(0)
A
0

Got it. I changed the file extension to js.erb

then in the js.erb file, I added the following lines:

var d=new Date();
var curr_hour=d.getHours();
var curr_min=d.getMinutes();
$('div#noid').html("<h1>The Current time is</h1>"+curr_hour+":"+curr_min)
Ataxia answered 15/3, 2011 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.