1

Rails はselect_tagデフォルトで name 引数から id と name を生成します:

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

しかし、 and属性selectなしで生成したい場合はどうなるでしょうか? idname
このような:

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

空の name 引数は機能しません。空の 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 に答える