简体   繁体   中英

Rails landing page password authentication

I want to create a 'Coming Soon' landing page for my app. It's a fully functional app, but while we are in beta I want to have a landing page with a password to control access while we are still testing. Once someone enters the correct password on the landing page then they can access the app. NOTE: this landing page password is different than a user account password.

Here is my view in "landing_password.html.erb":

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

And here is my pages_controller:

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

end

But when the password is 'correct', meaning when I type in 'test', it does not complete the redirect to home path. Anyone know why it doesnt work?

It seems like you have a typo in the form definition; you use :text , but shouldn't that be :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 %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM