在 Rails 3 中,link_to_function 消失到哪里去了? [英] Where did link_to_function disappear to in Rails 3?

查看:45
本文介绍了在 Rails 3 中,link_to_function 消失到哪里去了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在玩 Rails 3 beta,注意到 link_to_function 现在不见了.我认为有一种替代方法可以实现相同的结果(onclick 事件?),但我想知道是否有更多的 Rails-3'y 方法来做到这一点.TIA.

I was just playing around with Rails 3 beta and noticed that link_to_function is now gone. I presume there's an alternate method of achieving the same result (onclick event?) but I was wondering if there's a more Rails-3'y way of doing it. TIA.

推荐答案

Rails 3 似乎已经取消了 Prototype Helper,取而代之的是一种不那么突兀/JS 库不可知的方法.目标是消除所有由 Rails 生成的内联 javascript.Prototype Helper 生成了几乎所有的 javascript.

Rails 3 seems to have done away with Prototype Helper in favour of a less obtrusive/JS library agnostic approach. The goal is to eliminate all inline javascript generated by Rails. Prototype Helper generated pretty much all of the javascript.

现在,只要提供 :remote => true 选项,任何非远程助手变体都会为您选择的 JS 库中的远程调用生成正确的 javascript.

Now any of the non remote variants of helpers will generate the proper javascript for a remote call in your JS library of choice just by supplying the :remote => true option.

不幸的是,这不适用于 x to 函数方法.目前,原型遗留助手不再是 Rails 的核心部分.

Unfortunately this doesn't hold true for the x to function methods. For the time being there are the prototype legacy helpers which are no longer a core part of Rails.

您还可以使用 ActionView::Helpers::PrototypeHelper::JavascriptGenerator::GeneratorMethods 中定义的调用来向 :onclick 提供 javascript 代码作为 link_to 的 html_option,但这并不完全正确.

You could also use call as defined in ActionView::Helpers::PrototypeHelper::JavascriptGenerator::GeneratorMethods to supply javascript code to :onclick as an html_option for link_to, but that's not exactly pretty.

示例:

Rails < 3                      | Rails 3
link_to_remote "target", url   | link_to "target", url, :remote => true
form_remote_for @post          | form_for @post, :remote => true

等等....

或者类似的东西.我很难找到官方文件来支持我的声明.所以发行说明现在必须做.

Or something to that effect. I'm having trouble finding official documentation to back up my claims. So the release notes will have to do for now.

在使用它之前,您需要包含正确的 js 源文件.确保您正在加载prototype.js 和rails.js,或者在它们的位置加载选择JS 框架的库和驱动程序.

Before you can use it, you'll need to include the proper js source files. Ensure that you are loading prototype.js and rails.js, or the library and driver for JS framework of choice in their place.

请记住,Rails 3 现在处于测试阶段.但这并不意味着它已经完成了.老实说,我不知道如何替换 link_to_function.它违背了不引人注目的 javascript 的理想.

Remember, Rails 3 is in beta now. But that doesn't mean it's done. I honestly have no idea how link_to_function will be replaced. It goes against the ideal of unobtrusive javascript.

这篇关于在 Rails 3 中,link_to_function 消失到哪里去了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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