使用js.rjs呈现内联内容 [英] Using js.rjs to render inline content

查看:107
本文介绍了使用js.rjs呈现内联内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力提高对Rails的了解.我试图在一个简单的代码中使用js.rjs. 这是视图:

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>

这是控制器:

class DemoController < ApplicationController

    def say_when

      respond_to do |format|
        format.js
      end    

    end

end

我有如下的views/Say_when.js.rjs:

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?

推荐答案

知道了. 我将文件扩展名更改为js.erb

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

然后在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)

这篇关于使用js.rjs呈现内联内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆