This file contains hidden or 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
| /* | |
| * Ecrire une fonction qui prend en paramètre un nombre N et qui va afficher pour chaque nombre de 1 à N : | |
| * Fizz si le nombre est divisible par 3 | |
| * Buzz si le nombre est divisible par 5 | |
| * FizzBuzz si le nombre est divisible par 3 ET par 5 | |
| * Le nombre lui-même dans le reste du temps | |
| */ | |
| function fizzbuzz(n) { | |
| for (let i = 1; i <= n; i += 1) { |
This file contains hidden or 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
| FROM ubuntu:14.04 | |
| RUN apt-get update | |
| RUN apt-get install -y software-properties-common git build-essential libxml2-dev libxslt-dev zlib1g-dev libmysqlclient-dev libpq-dev | |
| RUN apt-add-repository ppa:brightbox/ruby-ng | |
| RUN apt-get update | |
| RUN apt-get install -y ruby2.1 ruby2.1-dev | |
| RUN gem install bundler -v 1.17.3 | |
| RUN gem install json -v 1.8.3 |
This file contains hidden or 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
| var express = require('express'); | |
| var app = express(); | |
| app.get('/', function(req, res) { | |
| res.send('Homepage'); | |
| }); | |
| app.get('/news', function(req, res) { | |
| res.send('News'); | |
| }); |
This file contains hidden or 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
| var express = require('express'); | |
| var app = express(); | |
| // Page d'accueil | |
| app.get('/', function(req, res) { | |
| // Nous allons simuler une erreur, pour cela nous appelons le prochain middleware en lui passant une erreur | |
| next("Insérez l'erreur ici..."); // Ne pas oublier de lui passer un paramètre sinon le middleware qui gère les erreurs ne sera jamais appelé | |
| }) | |
| // Middleware qui gère les erreurs (4 paramètres) |
This file contains hidden or 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
| var express = require('express'); | |
| var app = express(); | |
| // Middleware qui intercepète toutes les requêtes entrantes | |
| app.use(function(req, res, next) { | |
| console.log('Nouvelle requête entrante', req); | |
| /* Nous avons maintenant 2 choix : | |
| * - Arrêter la requête : en utilisant res.render() ou res.json() ou encore res.send() |
This file contains hidden or 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
| books = Book.all.includes(:author).limit(10) # Charge les livres présents dans notre database ainsi que les auteurs de chaque livre (1 requête SQL) | |
| books.each do |book| | |
| puts book.author.name # Aucune requête SQL ne sera éxecutée à ce niveau | |
| end |
This file contains hidden or 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
| books = Book.all.limit(10) # Charge les books présents dans notre database (1 requête SQL) | |
| books.each do |book| | |
| puts book.author.name # Pour chaque livre, effectue une requête SQL pour récupérer le nom de l'auteur | |
| end |
This file contains hidden or 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 'rails_helper' | |
| RSpec.describe "articles/show.html.erb", type: :view do | |
| context "when user is admin" do | |
| it "renders h2" do | |
| session[:user_id] = 1 # Nous supposons ici que le user avec un ID de 1 est automatiquement est un admin (pour des raisons de simplicité) | |
| article = FactoryGirl.create(:article) # Nous utilisons Factory Girl pour créer notre article | |
| assign :article, article # Rends l'article que nous venons de créer accessible à la vue | |
This file contains hidden or 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
| <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> | |
| <% if current_user.admin? %> | |
| <h2>Administration</h2> | |
| <p><%= link_to "Supprimer cet article", nil %></p> | |
| <% end %> |