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
# Q1 - How do you create a Rails app? | |
# TODO: rails? | |
rails new project-name --database=postgresql | |
# Q2 - How do you start coding a Rails project? Give the right sequence. | |
# '1. Coding the views?' | |
# '2. Coding the controllers?' | |
# '3. Coding the models?' | |
# TODO: 1, 2, 3? | |
3,2,1 |
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
require 'pry-byebug' | |
class Task | |
attr_reader :id | |
attr_accessor :title, :description, :done | |
def initialize(attributes = {}) | |
@id = attributes[:id] | |
@title = attributes[:title] | |
@description = attributes[:description] | |
@done = attributes[:done] || 0 |
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
# http://airbnb.com/flats/42 | |
SELECT * FROM flats | |
WHERE id = 42 | |
# https://github.com/users/jonnygates | |
SELECT * FROM users | |
WHERE username = 'jonnygates' |
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
require_relative 'view' | |
require_relative 'recipe' | |
class Controller | |
def initialize(cookbook) | |
@cookbook = cookbook | |
@view = View.new | |
end | |
def list |
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
require_relative 'view' | |
require_relative 'repo' | |
require_relative 'controller' | |
require_relative 'router' | |
view = View.new | |
repo = Repo.new | |
controller = Controller.new(view, repo) | |
router = Router.new(controller) |
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
require_relative 'app/repositories/meal_repository' | |
require_relative 'app/controllers/meals_controller' | |
require_relative 'router' | |
csv_file = 'data/meals.csv' | |
meal_repository = MealRepository.new(csv_file) | |
meals_controller = MealsController.new(meal_repository) | |
router = Router.new(meals_controller) |
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
require_relative 'patient' | |
class Room | |
attr_accessor :id | |
class RoomCapacityError < Exception; end | |
# STATE | |
# capacity - integer | |
# clean - boolean | |
# patients - array |
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
require_relative 'cookbook' # You need to create this file! | |
require_relative 'controller' # You need to create this file! | |
require_relative 'router' | |
csv_file = File.join(__dir__, 'recipes.csv') | |
cookbook = Cookbook.new(csv_file) | |
controller = Controller.new(cookbook) | |
router = Router.new(controller) |
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
class Repository | |
def initialize | |
@tasks = [] | |
end | |
def add(task) | |
@tasks << task | |
end | |
def all |
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
require "sqlite3" | |
db = SQLite3::Database.new("chinook.sqlite") | |
# List all customers (name + email), ordered alphabetically (no extra information) | |
def query_1(db) | |
query = <<-SQL | |
SELECT first_name, last_name, email | |
FROM customers | |
ORDER BY first_name asc | |
SQL |
NewerOlder