为什么 f.submit 在 Rails 3.1 中不生成 id 属性? [英] Why does f.submit not generate an id attribute in Rails 3.1?

查看:37
本文介绍了为什么 f.submit 在 Rails 3.1 中不生成 id 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,以下 jquery 脚本在 Rails 3.1 中失败,因为它没有找到元素.

I had an issue where the following jquery script was failing in Rails 3.1 due to it not finding the element.

jquery

member_submit_button = $("#member_submit");

哈姆

= form_for @member do |f|
...
    f.submit "Update details", :class => "member_submit_button bluebutton"

在 Rails 3.0 中这工作正常,我追踪到 Rails 3.1 没有生成 id 属性.在 rails 3.0 中,标签 id = "member_submit".

In Rails 3.0 this works fine, and I tracked it down to Rails 3.1 not generating the id attribute. In rails 3.0 a tag id = "member_submit".

这当然可以通过将 :id => "member_submit" 参数添加到 f.submit 调用中来轻松解决.但我想知道这种变化的原因是什么,因为我没有在任何地方看到过这种情况.

This of course is easily fixed by adding the :id => "member_submit" parameter to the f.submit call. But I wanted to know what the reason was for this change as I have not seen this documented anywhere.

推荐答案

我从 Rails 3.0 升级到 3.1,并注意到我的规范之一由于缺少相同的 ID 属性而失败.谷歌搜索显示,这是 Rails 3.1 的预期行为,如相应的 发行说明(请参阅第.5.3 - 动作视图"):

I upgraded from Rails 3.0 to 3.1 and noticed one of my specs failing due to the same missing ID attribute. A bit of googling revealed that this is an expected behaviour for Rails 3.1, as specified in the respective Release Notes (see sect. "5.3 - Action View"):

提交表单助手不再生成 id object_name_id".

The submit form helper does not generate an id "object_name_id" anymore.

即使我的信息没有完全回答你的问题,因为我无法告诉你为什么 Rails 团队决定做出这个改变,至少你可以确定这不是 Rails 缺陷,而是在那个表格助手.;)

Even if my message doesn't answer your question entirely, as I can't tell you why the Rails team decided to make this change, at least you can be sure that that's not a Rails defect, but rather a change in that form helper. ;)

这篇关于为什么 f.submit 在 Rails 3.1 中不生成 id 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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