Skip to content

Instantly share code, notes, and snippets.

View dedemenezes's full-sized avatar

André Menezes dedemenezes

View GitHub Profile

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 : : ...

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 : / ...

It's not a rule, it's a convention. What is important is that you show employers you know how to write a meaningful commit message so you have a structured commit history.

❌ git commit -m "finally fixed that bug yooo!"

  1. Commits MUST be prefixed with a type, which consists of a noun, featfixrefactor etc., followed by a colon and a space.
  2. The type feat MUST be used when a commit adds a new feature to your application.
  3. The type fix MUST be used when a commit represents a bug fix for your application.
  4. The commit message MUST be imperative (present tense). Think, if I apply that commit what will it do? “This commit will…..”

✅ git commit -m "feat: add restaurant grid to index"

puts '*' * 50
puts ' ' * 4 + '🎄 Welcome to your Christmas gift list 🎄'
puts '*' * 50
gift_list = [
{ name: 'Flamengo T-Shirt', status: false },
{ name: 'Christmas Socks', status: true }
# User starts with 100 euros
# user looses 10 when loosing
# user wins 50 when winning
# User can play until they are BROKE
# 1. create a wallet for the user (store the user balance)
wallet = 20
# 2. Make it a loop
# 3. Increase/Decrease the money into the wallet (update user balance)
# METHOD
# piece of code that we want to be able to reuse
# 1. name
# 2. it has parameters or not => THE ORDER matter!!!
# 3. returns something
def calculator(first_number, second_number, operator)
# if operator == '+'
# result = first_number + second_number
# elsif operator == '-'

How to think about your features

Something extremely important for you to know when preparing your trello cards and actually coding your features:

Think about FEATURES (example: search functionality, build CSS componentes) OR USER STORIES (create a new restaurant, save a post as your favourite), NEVER about the MVC layers

Examples of GOOD features:

  • Implement the New and Create for Restaurants/Cars/Invoices/etc. (this includes routes + controller + new and create actions + strong params + new.html.erb + form + TESTING THE FEATURE!!!!)

  • Implement the definitive CSS for Forms (this includes building the CSS classes, adding them to the existing forms of the application, showing to your teammates how to do the same for future forms)

Stimulus JS

Stimulus has three main parts

  1. Controller
  2. Actions
  3. Targets

Controller

Just like in our ruby apps, the controller is the maneger. The one responsible for the Javascript behaviour we want to implement. In order to create a controller we must follow the Naming Convention ⤵️

# TODO: you can build your christmas list program here!
# Pseudo-code:
# Define gift list as an ARRAY
gift_list = [{ 'name' => 'Laptop', 'status' => true }, { 'name' => 'Car', 'status' => false }]
# 1. Welcome
puts "Welcome to your Christmas gift list"
action = 'start' # initialize variable
# Use the MAP iterator to convert the variable hogwarts, array of arrays, into an array of hashes.
# Those hashes should have two keys: :name and :house
hogwarts = [['hermione', 'griffyndor'], ['draco', 'slytherin'], ['luna', 'ravenclaw'], ['cedric', 'hufflepuff']]
# PSEUDO CODE
p hogwarts
# 1. go over the hogwarts array (MAP)
hogwarts = hogwarts.map do |inner_array|
# p inner_array[0]