【问题标题】:Change id in simple form以简单的形式更改 id
【发布时间】:2012-01-21 13:25:50
【问题描述】:

如何改变默认的id或者class,生成简单的表单:

= simple_form_for(@account, url: account_url, validate: true, wrapper: :inline, html: { method: :put }) do |f|

html:

<form accept-charset="UTF-8" action="http://mikhail.smackaho.st:3000/account" class="edit_account" data-validate="true" id="edit_account_4f15c0a487f4463d8d000004" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="_method" type="hidden" value="put"><input name="authenticity_token" type="hidden" value="BZFZUGlbZU2ILGR/fdMW5QWNdDgWNPvGpZR13LFwhmw="></div>

      <div class="inputs">
        <div class="clearfix string required"><label class="string required  " for="account_company_name">Company name <abbr title="required">*</abbr></label><div class="input"><input autofocus="autofocus" class="string required " data-validate="true" id="account_company_name" name="account[company_name]" size="50" type="text" value="mikhail"></div></div>
        <div class="actions">
        <input class="btn primary" name="commit" type="submit" value="Update">
        <button class="btn" name="button" type="reset">Cancel</button>
      </div>
    </form>

帐户 - 单一资源。 我想要像edit_account这样没有id_hash的id

【问题讨论】:

    标签: ruby-on-rails simple-form


    【解决方案1】:

    html 选项中指定id

    = simple_form_for @account, url: account_url, wrapper: :inline, html: { method: :put, id: :edit_account } do |f|
    

    【讨论】:

      【解决方案2】:

      这个问题是模棱两可的,所以请注意,如果您试图更改表单中某个元素的 id 而不是整个表单的 id,那么您应该使用input_html: { id: :select_special }

      【讨论】:

        猜你喜欢
        • 2014-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-08
        相关资源
        最近更新 更多