Last active
August 4, 2022 00:29
-
-
Save Justin-Bento/2d49b79eb2b6cf232d2cd19236fd4022 to your computer and use it in GitHub Desktop.
Custom Params For Devise Auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app > controllers > application_controller.rb | |
# Before | |
class ApplicationController < ActionController::Base | |
end | |
# ------------------------------------------------------------------------------------------------------------ | |
# After | |
class ApplicationController < ActionController::Base | |
before_action :configure_permitted_parameters, if: :devise_controller? | |
protected | |
def configure_permitted_parameters | |
devise_parameter_sanitizer.permit(:sign_up, keys: [:firstname, :lastname]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app > devise > registrations | |
# Before | |
<h2>Sign up</h2> | |
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> | |
<%= render "devise/shared/error_messages", resource: resource %> | |
<div class="field"> | |
<%= f.label :firstname %><br /> | |
<%= text_field_tag :firstname, autofocus: true, autocomplete: "First Name" %> | |
</div> | |
<div class="field"> | |
<%= f.label :lastname %><br /> | |
<%= text_field_tag :lastname, autofocus: true, autocomplete: "Last Name" %> | |
</div> | |
<div class="field"> | |
<%= f.label :email %><br /> | |
<%= f.email_field :email, autofocus: true, autocomplete: "email" %> | |
</div> | |
<div class="field"> | |
<%= f.label :password %> | |
<% if @minimum_password_length %> | |
<em>(<%= @minimum_password_length %> characters minimum)</em> | |
<% end %><br /> | |
<%= f.password_field :password, autocomplete: "new-password" %> | |
</div> | |
<div class="field"> | |
<%= f.label :password_confirmation %><br /> | |
<%= f.password_field :password_confirmation, autocomplete: "new-password" %> | |
</div> | |
<div class="actions"> | |
<%= f.submit "Sign up" %> | |
</div> | |
<% end %> | |
<%= render "devise/shared/links" %> | |
# ---------- | |
After | |
<h2>Sign up</h2> | |
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> | |
<%= render "devise/shared/error_messages", resource: resource %> | |
<div class="field"> | |
<%= f.label :firstname %><br /> | |
<%= f.text_field :firstname, autofocus: true, autocomplete: "First Name" %> | |
</div> | |
<div class="field"> | |
<%= f.label :lastname %><br /> | |
<%= f.text_field :lastname, autofocus: true, autocomplete: "Last Name" %> | |
</div> | |
<div class="field"> | |
<%= f.label :email %><br /> | |
<%= f.email_field :email, autofocus: true, autocomplete: "email" %> | |
</div> | |
<div class="field"> | |
<%= f.label :password %> | |
<% if @minimum_password_length %> | |
<em>(<%= @minimum_password_length %> characters minimum)</em> | |
<% end %><br /> | |
<%= f.password_field :password, autocomplete: "new-password" %> | |
</div> | |
<div class="field"> | |
<%= f.label :password_confirmation %><br /> | |
<%= f.password_field :password_confirmation, autocomplete: "new-password" %> | |
</div> | |
<div class="actions"> | |
<%= f.submit "Sign up" %> | |
</div> | |
<% end %> | |
<%= render "devise/shared/links" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Before | |
Form Input | |
[#<User id: 1, email: "michael@example.com", firstname: nil, lastname: nil, created_at: "2022-08-03 18:33:26.894118000 +0000", updated_at: "2022-08-03 18:33:26.894118000 +0000">, | |
Form Input | |
#<User id: 2, email: "john.doe@example.com", firstname: nil, lastname: nil, created_at: "2022-08-03 19:07:04.798996000 +0000", updated_at: "2022-08-03 19:07:04.798996000 +0000">, | |
Manual Input | |
#<User id: 3, email: "jane.doe@example.com", firstname: "Jane", lastname: "Doe", created_at: "2022-08-03 19:10:31.575228000 +0000", updated_at: "2022-08-03 19:10:31.575228000 +0000">] | |
# ----------------------------------------------------------- | |
# After Strong Typed | |
=> [#<User id: 1, email: "john.doe@example.com", firstname: "John ", lastname: "Doe", created_at: "2022-08-03 23:37:17.951277000 +0000", updated_at: "2022-08-03 23:37:17.951277000 +0000">] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment