⚠️ ,和select不一样,不能简写。
解析:
<option selected="selected" value="en">English</option>
<option value="es">ESpañol</option>
</select>
理解:
api文档实例
select_tag "credit_card", options_for_select([ "VISA", "MasterCard" ], "MasterCard")
# => <select id="credit_card" name="credit_card">
<option>VISA</option>
# <option selected="selected">MasterCard</option>
</select>
select和select_tag的区别,类就不一样
select方法属于ActionView::Helpers::FormBuilder
AFormBuilder
object is associated with a particular model object and allows you to generate fields associated with the model object.
<%= form.select ( :locale, options_for_select(LANGUAGE, I18n.locale.to_s))%>
...
(可以简写 <%= form.select( :locale, LANGUAGES)%>)
配合chrome的inspect功能,可以看到效果,和错误
解析为html:
<option selected="selected" value="en">English</option>
<option value="es">ESpañol</option>
</select>
<%= javascript_tag "$('.locale input').hide()"%>
Returns a JavaScript tag with the content
inside. Example:
javascript_tag "alert('All is good')"
Returns:
<script> //<![CDATA[ alert('All is good') //]]> </script>