password_field_tag将类规范作为值(rails bootstrap上的ruby)(password_field_tag takes class specification as value (ruby on rails bootstrap))

我正在为rails应用程序上的ruby构建一个简单的登录页面,并希望使用bootstrap设置我的表单样式。 到目前为止,我已经能够通过添加引导类(使用form_for循环)来设置所有内容的样式,但为此我使用的是form_tag,现在我的密码字段不会占用该类。 相反,我认为它正在使用它作为价值。 谁能告诉我如何解决这个问题? 谢谢

这是我的观点:

<h1>Log in</h1> <%= form_tag sessions_path do %> <div class="form-group"> <%= label_tag :email %> <%= text_field_tag :email, params[:email], class:'form-control' %><br/> <%= label_tag :password %> <%= password_field_tag :password, class:'form-control' %><br /> <%= submit_tag "Log in", class:'btn btn-primary' %> </div> <% end %>

I'm building a simple login page for my ruby on rails app and want to style my forms using bootstrap. So far I've been able to style everything by adding bootstrap classes (while using a form_for loop), but for this I'm using a form_tag and now my password field won't take the class. Instead I think it's using it as value. Can anyone tell me how to fix this? Thanks

Here's my view:

<h1>Log in</h1> <%= form_tag sessions_path do %> <div class="form-group"> <%= label_tag :email %> <%= text_field_tag :email, params[:email], class:'form-control' %><br/> <%= label_tag :password %> <%= password_field_tag :password, class:'form-control' %><br /> <%= submit_tag "Log in", class:'btn btn-primary' %> </div> <% end %>

最满意答案

password_field_tag方法的签名是:

password_field_tag(name = "password", value = nil, options = {})

第二个参数是值,这就是你这样看的原因。 我建议的答案是写这个:

<%= password_field_tag :password, nil, class:'form-control' %><br/>

以下是rails中Form Kal Helper的链接: ActionView :: Helpers :: FormTagHelper

The signature for the password_field_tag method is:

password_field_tag(name = "password", value = nil, options = {})

The second parameter is the value, which is why you see it that way. My suggested answer would be to write this instead:

<%= password_field_tag :password, nil, class:'form-control' %><br/>

Here is a link to the Form Tag Helper in rails: ActionView::Helpers::FormTagHelper

更多推荐