Rails 3 渲染 JS 不执行任何操作

发布于 2024-10-12 14:52:05 字数 795 浏览 6 评论 0原文

我是一个巨大的初学者,我正在学习 Rails 3 和 RJS 请求并进行一些练习。 我正在使用从教程中获得的以下内容进行 RJS 测试。

以下是我的index.rhtml。在我的标题中,我有一些我注意到人们发布的标签,例如 javascript_include_tag 和 csrf_meta_tag

 <div id="rjs">I will be updated.</div>

以下行肯定是不正确的。这可能是我的问题。我见过不同的 Rails 2 实现,但我读到在 Rails 3 中它已经发生了变化,并且似乎无法让它工作。我的网址有问题。我无法正确设置我的 url 语句,这可能是问题所在。

 <%= link_to "Test out RJS!", rjs_path(@rjs), :remote => true %>

我的 hello.rjs 文件具有以下内容

page.replace_html "rjs", "<b>See!</b>"

我的控制器如下

class RjsController < ApplicationController
def hello
end

从我遵循的指南中,当您单击链接时,应将原始的“我将更新”切换为“查看”,但在我的情况下,当我单击链接时没有任何反应 。

有人能够帮助我处理我的 link_to 行,并可能给我一个解释,为什么它是这样写的 谢谢

I am a huge beginner and I am learning and doing some practice work with rails 3 and RJS requests.
I am doing a RJS test with the following which I got from a tutorial.

The following is in my index.rhtml. In my header I have the tags I have noticed people post around such as teh javascript_include_tag and csrf_meta_tag

 <div id="rjs">I will be updated.</div>

The Following line is for sure incorrect. Which is probably my problem. I have seen different rails 2 implementations but I've read that in Rails 3 it has changed and can't seem to get it working. My Url is the problem. I can't set up my url statment correctly which is probably the problem.

 <%= link_to "Test out RJS!", rjs_path(@rjs), :remote => true %>

My hello.rjs file has the following

page.replace_html "rjs", "<b>See!</b>"

My controller is the following

class RjsController < ApplicationController
def hello
end

From the guide I was following this should switch the original "I will be updated" to "See" when you click the link but in my case nothing happens when I click the link
end

Would someone be able to help me with my link_to line and possibly give me a explanation as too why it is written the way it is. Thank You

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空‖城人不在 2024-10-19 14:52:05

您可以像这样在控制器顶部添加 :respond_to 吗?

class RjsController < ApplicationController   
  respond_to :js

  def hello   
  end

end

希望有效。

Can you add :respond_to on top of your controller like this?

class RjsController < ApplicationController   
  respond_to :js

  def hello   
  end

end

Hope that works.

并安 2024-10-19 14:52:05

我正在使用 JQuery 和 JRails 并在 firefox 中检查它告诉我 JQuery 未定义。我认为我在 Rails 应用程序中的所有设置都正确。抱歉,我是该网站的新手。另外放置 respond_to :js 并没有改变任何东西

我的错误让我看到了我在为 JQuery 添加 Unbotrusive 脚本适配器的适配器时覆盖的 Rails.js 行

})( jQuery );

I am using JQuery and JRails and checking in firefox it tells me JQuery is not defined. I thought I set everything up in my rails app correctly. Sorry I am new to the site. Also putting respond_to :js did not change anything

My error brings me to this line of my rails.js that i overwritten when adding the adapter for Unbotrusive scripting adapter for JQuery

})( jQuery );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文