Ruby-on-rails 以简单的形式更改 id

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8953324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 02:40:24  来源:igfitidea点击:

Change id in simple form

ruby-on-railssimple-form

提问by Mikhail Grishko

How change default id or class, which produce simple form:

如何更改生成简单表单的默认 id 或类:

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

html:

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>

Account - single resource. I want to have id like edit_account without id_hash

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

回答by Micha? Czapko

Specify the idwithin the htmloption:

idhtml选项中指定:

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

回答by Obromios

The question is ambiguous, so note that if you are trying to change the id of an element in the form rather than the id of the whole form, then you should use input_html: { id: :select_special }.

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