[英]Using Bootstrap with Bcrypt sessions form in Rails
I'm using Bcrypt and has_secure_password for user authentications in a basic Rails app. 我在基本的Rails应用程序中使用Bcrypt和has_secure_password进行用户身份验证。 For all of my other forms in the app I'm using the gem bootstrap_form which enables me to have nice looking bootstrap forms rather than the ugly default ones.
对于应用程序中的所有其他表格,我使用的是gem bootstrap_form,这使我可以拥有漂亮的Bootstrap表格,而不是难看的默认表格。
The problem is that Bcrypt doesn't seem to allow this for the sessions login form. 问题在于Bcrypt似乎不允许会话登录表单使用此功能。 It would be really good if I were able to integrate Bootstrap into this login form so that I don't need to play around with css for a long time.
如果我能够将Bootstrap集成到此登录表单中,这样我就不需要长时间使用CSS,那将是非常好的。
My sessions/new.erb looks like this: 我的sessions / new.erb看起来像这样:
<%= form_tag sessions_path do %>
<h3>Log In</h3>
<div class="form-group">
<%= text_field_tag :email, params[:email], placeholder: 'Email',
:class => 'class_name' %>
</div>
<div class="field">
<%= password_field_tag :password, params[:password], placeholder:
'password', :class => 'class_name' %><br>
<%= link_to 'Sign up', new_user_path %>
</div><br>
<div class="actions"><%= submit_tag "Log In" %></div>
<% end %>
And my sessions controller looks like this: 我的会话控制器如下所示:
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to new_comment_path, notice: "Logged in!"
else
flash.now.alert = "Email or password is invalid"
render "new"
end
end
def destroy
session[:user_id] = nil
redirect_to root_url, notice: "Logged out!"
end
Thanks :-) 谢谢 :-)
But you'r probably doing 但是你可能正在做
<%= bootstrap_form_tag sessions_path do %>
, <%= bootstrap_form_tag sessions_path do %>
,
instead of 代替
<%= bootstrap_form_tag url: sessions_path do |f| %>
Answer: Try like this 答:像这样尝试
<%= bootstrap_form_tag url: sessions_path do |f| %>
<%= f.email_field :email %>
<%= f.password_field :password %>
<%= f.check_box :remember_me %>
<%= f.submit "Log In" %>
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.