1

select_tagRails默认为 name 参数生成 id 和 name :

select_tag "people", "<option>David</option>".html_safe
# => <select id="people" name="people"><option>David</option></select>

但是,如果我们想生成select没有 andidname属性怎么办?
像这样:

<select><option>David</option></select>

空名称参数不起作用,空 html 属性仍然存在:

select_tag "", "<option>David</option>".html_safe
# => <select id name><option>David</option></select>

手动idname分配不起作用

select_tag "people", "<option>David</option>".html_safe, id: false, name: false
# => <select id=false name=false><option>David</option></select>
select_tag "people", "<option>David</option>".html_safe, id: '', name: ''
# => <select id name><option>David</option></select>
4

1 回答 1

3

id并且name可以通过分配nil给它来删除:

select_tag nil, "<option>David</option>".html_safe, id: nil
# => <select><option>David</option></select>
于 2013-07-13T17:44:09.267 回答