Rails 的 link_to_function 弃用状态? [英] Status of Rails' link_to_function deprecation?
问题描述
Rails 中 link_to_function
Javascript 助手的状态是什么?我在this stackoverflow question中读到,这是在 Rails 3.0 中弃用,然后不推荐使用,然后在 3.2.4 中再次弃用.这是我可以依赖并教给学生的东西吗?我刚刚阅读了 发布Rails 3.2.8 的注释(来自搜索):
What is the status of the link_to_function
Javascript helper in Rails? I read, including in this stackoverflow question, that it was deprecated in Rails 3.0, then undeprecated, then deprecated again in 3.2.4. Is it something I can depend on and teach students? I just read the release notes (from a search) for Rails 3.2.8:
恢复了 button_to_function 和 link_to_function 助手的弃用.拉斐尔·门东萨·弗兰萨
Reverted the deprecation of button_to_function and link_to_function helpers. Rafael Mendonça França
现在情况如何?
推荐答案
link_to_function
在 3-2-stable
分支和将来它不会在 3-2-stable
中被弃用.但是它IS 在当前的 master 分支中被弃用,并且在 Rails 4.0 发布时将被弃用.所以我想它会从 4.1 中的 rails 代码中删除.所以你可以教学生这样做(来自 rails 4 更新日志):
link_to_function
is NOT deprecated in 3-2-stable
branch and it won't be deprecated in 3-2-stable
in future. But it IS depreacated in current master branch and will be deprecated in Rails 4.0 when it releases. So I guess it will removed from rails code in 4.1.
So you can teach students to do this (from the rails 4 changelog):
我们建议改用 Unobtrusive JavaScript.例如:
We recommend the use of Unobtrusive JavaScript instead. For example:
link_to "Greeting", "#", class: "nav_link"
$(function() {
$('.nav_link').click(function() {
// Some complex code
return false;
});
});
或
link_to "Greeting", '#', onclick: "alert('Hello world!'); return false", class: "nav_link"
这篇关于Rails 的 link_to_function 弃用状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!