Skip to content

Instantly share code, notes, and snippets.

@dedemenezes
Created February 23, 2024 19:29
Show Gist options
  • Save dedemenezes/aabaabed7b35c14764f7db0719a4d932 to your computer and use it in GitHub Desktop.
Save dedemenezes/aabaabed7b35c14764f7db0719a4d932 to your computer and use it in GitHub Desktop.

Full MVC Rails app

Model(s)

  • Model -> singular, eg: 'car' , 'child'
  • table -> plural, eg: 'cars', 'children'

Which columns/attributes should we add to our table? After give it a thought ⤵️

rails g model :ModelName <attribute_one>:<type> <attribute_two>/<type> ...

  • Check Migrations (add default values?)
  • Run migrations rails db:migrate
  • IS your schema correct? Check your schema file at db/schema.rb
  • Add Validations
  • Test crash your models:
    • rails c
    • Create a new one instance
    • Ensure validations with #valid?
    • Check validations errors using <instance>.errors.messages
  • Populate database with some data (seeds?)

Application part

  • Route -------> only the one you need at the moment
    • Syntax: verb '/<model_in_plural>', to: 'controller_name#action', as: :prefix
    • Example: get '/books/new', to: 'books#new', as: :new_book
  • Controller --> only the one you need at the moment
    • Define action method and think about which ActiveRecord method we should use
    • Example⤵️
    def new
      @book = Book.new
    end
  • View --------> only the one you need at the moment
    • Create html to display information
    • Example: new.html.erb

🔁 REPEAT 🔁 FOR 🔁 EVERY 🔁 USER 🔁 STORY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment