问题描述:

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

网友答案:

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

相关阅读:
Top