git log --reverse | head -n1 c4d7c9 2024-11-17 rails new -d postgresql --main bookmaker code fast means use what you know code fast means automate early
ApplicationRecord include Recoverable, Searchable encrypts :first_name, :last_name, :phone encrypts :email, deterministic: { fixed: false }, downcase: true normalizes :phone, with: ->(phone) { phone.delete '^0-9' } # @return [String] the full name of the user. def full_name [first_name, last_name].compact.join ' ' end … Write meaningful models Embrace the power of Active Record app/model/user.rb
ActiveSupport::Concern RECOVERY_LINK_EXPIRY_DURATION = 4.hours def recovery_token signed_id purpose: :recover, expires_in: RECOVERY_LINK_EXPIRY_DURATION end class_methods do def find_by_recovery_token(token) find_signed token, purpose: :recover end end end app/model/user/recoverable.rb
] do resource :session, only: %i[ destroy ] end resources :locations, only: %i[ new create ] resources :pets, only: %i[ new create ] do resources :items, only: %i[ edit update destroy ] end resources :bookings, only: %i[ new create show ] do resource :confirmation, only: %i[ new create ] end end Maintain resourceful routes Reduce surprise adopting the REST pattern con fi g/routes.rb
before_action { @booking = Booking.find params[:id] } # Show the form to confirm a booking def new end # Enqueue a job to confirm with the service provider # Immediately redirect to the booking page def create BookingConfirmationJob.perform_later @booking redirect_to @booking, status: :see_other end end app/controllers/bookings/con fi rmations_controller.rb
before_action { @booking = Booking.find params[:id] } # Show the form to confirm a booking def new end # Enqueue a job to confirm with the service provider # Immediately redirect to the booking page def create BookingConfirmationJob.perform_later @booking redirect_to @booking, status: :see_other end end app/controllers/bookings/con fi rmations_controller.rb
< ApplicationController def show @booking = Booking.find params[:id] end end <%= turbo_stream_from @booking %> class Booking < ApplicationRecord broadcasts_refreshes end app/model/booking.rb app/controllers/bookings_controller.rb app/views/bookings/show.html.erb
root_url # Enter valid contact data assert_text 'Let’s complete your contact information' fill_in 'First name', with: 'Flow' fill_in 'Last name', with: 'Test' fill_in 'ZIP code', with: '90210' fill_in 'Email address', with: '[email protected]' click_button 'Continue' assert_text 'What is your service address?' … Gain visibility over the code Mimic user behavior with ActionDispatch::SystemTestCase test/system/ fl ow_test.rb
<%= form.text_field :first_name %></label> <label> Last name <%= form.text_field :last_name %></label> <label> Email address <%= form.text_field :email %></label> <label> Phone number (optional) <%= form.text_field :phone %></label> <%= form.submit 'Continue' %> <% end %> Make it nice Pico CSS minimizes changes to HTML fi les with Pico CSS app/views/users/new.html.erb
Point to the main branch of Rails Contribute to open source Encrypt and normalize data Keep fi les short Generate documentation from code Stick to resourceful routes Run slow tasks asynchronously Favor system tests Enforce complete code coverage Pick a low-impact CSS framework Harness Turbo 8 for page speed Build native apps incrementally Thank you!