web-dev-qa-db-ja.com

単純な形式でIDを変更する

単純なフォームを生成するデフォルトのIDまたはクラスを変更する方法:

= 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>

アカウント-単一のリソース。 id_hashのないedit_accountのようなIDが欲しい

29
Mikhail Grishko

idオプション内でhtmlを指定します。

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

質問があいまいなので、フォーム全体のIDではなく、フォーム内の要素のIDを変更する場合は、input_html: { id: :select_special }を使用する必要があります。

1
Obromios