【问题标题】:Using js.rjs to render inline content使用 js.rjs 渲染内联内容
【发布时间】:2011-07-15 11:16:38
【问题描述】:

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

<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

我有如下观点/Say_when.js.rjs:

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

但是当点击“点击”链接时,什么也没有发生。我做错了什么?

【问题讨论】:

    标签: ruby-on-rails-3 rjs


    【解决方案1】:

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

    然后在 js.erb 文件中,我添加了以下几行:

    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)
    

    【讨论】:

      猜你喜欢
      • 2019-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 2014-06-10
      相关资源
      最近更新 更多