我在会话视图中自定义事物默认设置new.html.erb,因此它生成像
这样的Html代码 <form class="form-signin" role="form">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" class="form-control" placeholder="Email address" required autofocus>
<input type="password" class="form-control" placeholder="Password" required>
<label class="checkbox">
<input type="checkbox" value="remember-me"> Remember me
</label>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
我添加了以下行:html =&gt; {:class => 'form-signin', :role => 'form'}
代码如下。
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name),
:html => {:class => 'form-signin', :role => 'form'}) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end -%>
<div><%= f.submit "Sign in" %></div>
<% end %>
<%= render "devise/shared/links" %>
我不知道接下来要做什么来修改
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
所以它生成了这个:<input type="text" class="form-control" placeholder="Email address" required autofocus>
?? 谢谢!
答案 0 :(得分:2)
<%= f.text_field :email, placeholder: "Email address",
required: true, autofocus: true %>
应该工作。