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

时间:2011-07-18 18:45:39

标签: ruby-on-rails ruby-on-rails-3.1

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

此标记用于包含“无处”的空白选项,但现在文本框为空白,有人知道原因吗?

1 个答案:

答案 0 :(得分: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

表示您必须将:include_blank替换为:prompt。如果您想在选择字段中选择空白,请使用包含空白:)