Rails登陆页面密码验证

时间:2013-11-15 13:34:02

标签: ruby-on-rails authentication erb

我想为我的应用创建一个“即将推出”的目标网页。它是一个功能齐全的应用程序,但在我们处于测试阶段时,我想要一个带有密码的登录页面来控制访问,同时我们还在测试。一旦有人在登录页面上输入了正确的密码,他们就可以访问该应用程序。注意:此着陆页密码与用户帐户密码不同。

以下是“landing_password.html.erb”中的观点:

<%= simple_form_for :landing, html: { class: 'form-horizontal'} do |f| %>
  <%= f.input :text %>
  <%= f.button :submit, "Sign In" %>
<% end %>

这是我的pages_controller:

def landing
testpassword = 'test'
if params[:landing][:password] == testpassword
    redirect_to home_path
end

但是当密码是'正确'时,意味着当我输入'test'时,它不会完成重定向到主路径。任何人都知道它为什么不起作用?

1 个答案:

答案 0 :(得分:1)

好像你在表单定义中有拼写错误;您使用:text,但不应该是:password

<%= simple_form_for :landing, html: { class: 'form-horizontal'} do |f| %>
  <%= f.input :password, label: "Please enter your password" %>
  <%= f.button :submit, "Sign In" %>
<% end %>
相关问题