Why does f.submit not generate an id attribute in Rails 3.1?

那年仲夏 提交于 2019-12-12 16:06:30

问题


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");

haml

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

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".

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.


回答1:


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"):

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

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. ;)



来源:https://stackoverflow.com/questions/8238512/why-does-f-submit-not-generate-an-id-attribute-in-rails-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!