使用 js.rjs 渲染内联内容
我正在努力提高我对 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
我的views/Say_when.js.rjs 如下:
page.replace_html('noid', render(:text=>"OK"))
但是当单击“click”链接时,没有任何反应。我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道了。
我将文件扩展名更改为 js.erb
,然后在 js.erb 文件中添加了以下行:
Got it.
I changed the file extension to js.erb
then in the js.erb file, I added the following lines: