如何在form_helper中强制输入字段的ID?

时间:2012-06-12 21:13:54

标签: ruby-on-rails ruby-on-rails-3 devise

我希望我的输入iduser[email],而不是user_email。但我尝试的一切都行不通。

我正在使用最新版本的Devise来获取这些宝石。

这是我的表格:

  <%= form_for(resource, :as => resource_name, :class => "send-with-ajax", :url => user_registration_path(resource), :validate => true, :html => { :id => 'user_new' }) do |f| %>
                    <div class="six columns alpha"> 
      <%= f.text_field :email, :id => 'user[email]', :placeholder => "your-email@address.com", :input_html => {:autofocus => true}, :validate => true %>
                        </div>              
                        <div class="three columns sign-up alpha">
      <%= f.submit :label => "Submit", :value => "Sign Me Up!" %>
                          <div class="ajax-response"><%= devise_error_messages! %></div>
      </div>
  <% end %>

这是HTML制作的:

<form accept-charset="UTF-8" action="/users" class="formtastic user" data-validate="true" id="user_new" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="khstyw72jj44kkhaskdya3hkb3ba3lkxmw4=" /></div>
                        <div class="six columns alpha"> 
              <input data-validate="true" id="user_email" input_html="{:autofocus=&gt;true}" name="user[email]" placeholder="your-email@address.com" size="30" type="text" />
                            </div>              
                            <div class="three columns sign-up alpha">
              <input label="Submit" name="commit" type="submit" value="Sign Me Up!" />
                              <div class="ajax-response"></div>
              </div>
</form>

思想?

2 个答案:

答案 0 :(得分:2)

ID不能包含方括号,因此可能是Rails更改它的原因。

请参阅: What are valid values for the id attribute in HTML?What characters are allowed in DOM IDs?

答案 1 :(得分:0)

似乎我必须重新启动服务器才能反映form_helper更改。

所以:id => user[email]确实有用。