2013-07-13 27 views
0

Rails的默認從名稱參數生成select_tag編號和名稱:如何刪除ID和名稱從軌道屬性視圖助手

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

但是,如果我們想生成select沒有和idname屬性是什麼?
像這樣:

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

回答

1

idname可以刪除通過給它分配nil

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