初学者问题
我试图在行选择中添加{:include_blank => "Please select"}
。
%label Please choose the language you speak
.user-profile-select
%select{id: "user_language_language_id"}
- Language.active.each do |lang|
%option{value: lang.id}= lang.to_label
%input{type: "button", value: "ADD", id: "add_user_language"}
%span.note You can choose few
:coffeescript
$("#add_user_language").click ->
$.post #{my_user_languages_path.to_json},
format: 'js'
user_language:
language_id: $("#user_language_language_id").val()
false
我遇到haml错误或没有更改。谁能解释我做错了什么?
答案 0 :(得分:1)
%label Please choose the language you speak
.user-profile-select
%select{id: "user_language_language_id"}
%option{class: "prompt"} Please Select
- Language.active.each do |lang|
%option{value: lang.id}= lang.to_label
%input{type: "button", value: "ADD", id: "add_user_language"}
%span.note You can choose few
您可以提供默认"选项"在每个循环之前标记。 您可以使用表单帮助程序方法(select),您可以在其中传递数组和提示值。
select("lang", "lang_id", Language.active.collect {|p| [ p.name, p.id ] }, {:prompt => 'Please Select'})