【问题标题】:how to configure Rails tag to not generate HTML id如何配置 Rails 标签不生成 HTML id
【发布时间】:2012-04-21 04:28:05
【问题描述】:

如果您使用像 check_box_tag 这样的 Rails 助手,是否可以告诉它不要生成 HTML id 或者是唯一的选择来覆盖它?

【问题讨论】:

    标签: ruby-on-rails html-helper


    【解决方案1】:

    我不知道你为什么要这样做,但我相信你做不到。查看 check_box_tag 帮助器的代码:

    def check_box_tag(name, value = "1", checked = false, options = {})
      html_options = { "type" => "checkbox", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)
      html_options["checked"] = "checked" if checked
      tag :input, html_options
    end
    

    您可以做的最接近的方法是传递 nil,这将生成 id=""

    【讨论】:

    • 我只是不需要表格行中每个复选框的 id。我使用名称model_ids[],以便对复选框进行分组。 id 最终彼此重复。顺便说一句,空 ID 无效。 stackoverflow.com/questions/6535934/…
    猜你喜欢
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    相关资源
    最近更新 更多