默认情况下,Rails会从name参数为select_tag
生成id和名称:
select_tag "people", "<option>David</option>".html_safe
# => <select id="people" name="people"><option>David</option></select>
但是如果我们想要生成select
而没有id
和name
属性呢?
像这样:
<select><option>David</option></select>
空名称参数不起作用,空的html属性仍然存在:
select_tag "", "<option>David</option>".html_safe
# => <select id name><option>David</option></select>
手动id
和name
分配不起作用
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>
答案 0 :(得分:2)
id
和name
可以通过为其分配nil
来删除:
select_tag nil, "<option>David</option>".html_safe, id: nil
# => <select><option>David</option></select>