Last active
October 20, 2023 16:27
-
-
Save louishuyng/d95410068c87d992128a3898bea292a0 to your computer and use it in GitHub Desktop.
Rails 7 New Features
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
## Inquiry | |
"production".inquiry.production? # True | |
"active".inquiry.inactive? # False | |
## Normalizes | |
class User < ApplicationRecord | |
normalizes :email, with: ->(email) { email.strip.downcase } | |
end | |
## Generate Token For | |
class User < ApplicationRecord | |
generates_token_for : password_reset, expires_in: 15. minutes do | |
# BCrypt salt changes when password is updated | |
BCrypt:: Password. new (password_digest) .salt[-10..] | |
end | |
end | |
user.generate_token_for(:password_reset) | |
#=> "eyJfcmFpbHMiOnsiZGFOYSI6WzkwMjUOMTYzNSwiaC9oTkRJck9uL..." | |
User.find_by_token_for(:password_reset, params [: token]) | |
#=> User or nil |
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
## Find unsued routes | |
rails routes --unused |
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
## Strict Local | |
<# locals: (message:) -%> | |
<%= tag.div id: dom_id(message) do %> | |
<%= message %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment