oreoshake
oreoshake

Reputation: 4898

Select tag include blank behavior in rails 3.1 rc4

  <%= select_tag 'pseudo-attribute', options_for_select(...), :include_blank => 'Nowhere'%>

This tag used to include a blank option with "Nowhere" but now the text box is blank, does anyone know why that is?

Upvotes: 2

Views: 1202

Answers (1)

Gerry
Gerry

Reputation: 5336

Now the code for the select tag is (Rails 3.1.0.rc4)

  def select_tag(name, option_tags = nil, options = {})
    html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name

    if options.delete(:include_blank)
      option_tags = "<option value=\"\"></option>".html_safe + option_tags
    end

    if prompt = options.delete(:prompt)
      option_tags = "<option value=\"\">#{prompt}</option>".html_safe + option_tags
    end

    content_tag :select, option_tags, { "name" => html_name, "id" => sanitize_to_id(name) }.update(options.stringify_keys)
  end

which means you have to replace :include_blank with :prompt. Use include blank if you want a blank option in your select field :)

Upvotes: 8

Related Questions