1

Beginner question I'm trying to add {:include_blank => "Please select"} in line 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

I'm getting haml error or stay without changes. Who can explain what i'm doing wrong?

Jed Schneider
  • 14,085
  • 4
  • 35
  • 46
muzaparofff
  • 17
  • 1
  • 6

1 Answers1

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    

You can provide default "option" tag before the each loop. You can use form helper methods (select), where you can pass an array and a prompt value.

select("lang", "lang_id", Language.active.collect {|p| [ p.name, p.id ] }, {:prompt => 'Please Select'})
Pavan
  • 81
  • 3
  • Yeah I saw that too in api.rubyonrails.org, and i tried that too. Im getting haml error: "Inconsistent indentation: " \t" used for indentation, but the rest of the document was indented using 2 spaces." And I know what that mean. But i put this right and without 2 spaces. Thanks anyway! – muzaparofff Nov 02 '14 at 19:14
  • @muzaparofff find a way for your editor to replace tabs with spaces. tabs and spaces are not the same. – Jed Schneider Nov 03 '14 at 00:39