【发布时间】:2013-07-12 00:53:12
【问题描述】:
Rails 默认通过 name 参数为 select_tag 生成 id 和 name:
select_tag "people", "<option>David</option>".html_safe
# => <select id="people" name="people"><option>David</option></select>
但如果我们想生成没有 id 和 name 属性的 select 怎么办?
像这样:
<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>
【问题讨论】:
标签: html ruby-on-rails view helper ruby-on-rails-4