From bebf0ecbbe4982d8a02097680ffa2eb1d3242dce Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 27 Dec 2014 11:22:40 -0200 Subject: [PATCH] Simplify the logic to display the minimum password length hint There's no real need to pass 2 variables to the view to figure that out, we can simply display the message relying on whether or not the `@minimum_password_length` variable is present. --- CHANGELOG.md | 3 +++ app/controllers/devise_controller.rb | 3 +-- app/views/devise/passwords/edit.html.erb | 2 +- app/views/devise/registrations/new.html.erb | 2 +- .../templates/simple_form_for/passwords/edit.html.erb | 2 +- .../templates/simple_form_for/registrations/new.html.erb | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d774d442..39221519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ### Unreleased * enhancements + * The hint about minimum password length required both `@validatable` and `@minimum_password_length` + variables on the views, it now uses only the latter. If you have generated the views + relying on the `@validatable` variable, replace it with `@minimum_password_length`. * Added an ActiveSupport load hook for `:devise_controller` (by @nakhli) * Location fragments are now preserved between requests (by @jbourassa) * Added an `after_remembered` callback for the Rememerable module (by @BM5k) diff --git a/app/controllers/devise_controller.rb b/app/controllers/devise_controller.rb index 4ab8d570..589bd623 100644 --- a/app/controllers/devise_controller.rb +++ b/app/controllers/devise_controller.rb @@ -156,8 +156,7 @@ MESSAGE # Sets minimum password length to show to user def set_minimum_password_length - @validatable = devise_mapping.validatable? - if @validatable + if devise_mapping.validatable? @minimum_password_length = resource_class.password_length.min end end diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index a2ce2f5b..0ee12dd2 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -6,7 +6,7 @@
<%= f.label :password, "New password" %>
- <% if @validatable %> + <% if @minimum_password_length %> (<%= @minimum_password_length %> characters minimum) <% end %>
<%= f.password_field :password, autofocus: true, autocomplete: "off" %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 343b2656..5a238ce6 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -10,7 +10,7 @@
<%= f.label :password %> - <% if @validatable %> + <% if @minimum_password_length %> (<%= @minimum_password_length %> characters minimum) <% end %>
<%= f.password_field :password, autocomplete: "off" %> diff --git a/lib/generators/templates/simple_form_for/passwords/edit.html.erb b/lib/generators/templates/simple_form_for/passwords/edit.html.erb index 90500324..a938930b 100644 --- a/lib/generators/templates/simple_form_for/passwords/edit.html.erb +++ b/lib/generators/templates/simple_form_for/passwords/edit.html.erb @@ -7,7 +7,7 @@ <%= f.full_error :reset_password_token %>
- <%= f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @validatable) %> + <%= f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %> <%= f.input :password_confirmation, label: "Confirm your new password", required: true %>
diff --git a/lib/generators/templates/simple_form_for/registrations/new.html.erb b/lib/generators/templates/simple_form_for/registrations/new.html.erb index 4ea8fb95..34b4279e 100644 --- a/lib/generators/templates/simple_form_for/registrations/new.html.erb +++ b/lib/generators/templates/simple_form_for/registrations/new.html.erb @@ -5,7 +5,7 @@
<%= f.input :email, required: true, autofocus: true %> - <%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @validatable) %> + <%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %> <%= f.input :password_confirmation, required: true %>