Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Rails generates id and name for select_tag from name argument by default:

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

But what if we want to generate select without and id and name attributes?
Like this:

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

Empty name argument doesn't work, empty html attributes still exists:

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

Manual id and name assign doesn't work

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>
share|improve this question

1 Answer

up vote 1 down vote accepted

id and name can be removed by assigning nil to it:

select_tag nil, "<option>David</option>".html_safe, id: nil
# => <select><option>David</option></select>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.