选择标记包含rails 3.1 rc4中的空白行为

ore*_*ake 2 ruby-on-rails ruby-on-rails-3.1

  <%= select_tag 'pseudo-attribute', options_for_select(...), :include_blank => 'Nowhere'%>
Run Code Online (Sandbox Code Playgroud)

这个标签曾经包含一个带有"Nowhere"的空白选项,但现在文本框是空白的,有人知道为什么会这样吗?

Ger*_*rry 8

现在select标签的代码是(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
Run Code Online (Sandbox Code Playgroud)

这意味着你必须更换:include_blank:prompt.如果您想在选择字段中选择空白,请使用包含空白:)