Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Initiation à Ruby on Rails

Initiation à Ruby on Rails

Matthieu Segret

February 12, 2013
Tweet

More Decks by Matthieu Segret

Other Decks in Programming

Transcript

  1. • Langage interprété / orienté objet • Libre - Licence

    Ruby et GPL • Version 1.9.3 (bientôt 2.0) • Apparu en 1995 Ruby
  2. puts "Hello world" Ruby "ruby is cool".length # 12 -42.abs

    # 42 "Nice Day Isn't It?".downcase.split # ["nice", "day", "isn't", "it?"]
  3. class Book def initialize(name) @name = name end def name

    @name end end Ruby book = Book.new("Programming Ruby") book.name # "Programming Ruby"
  4. • Framework web écrit en Ruby • Libre - MIT

    • Version 3.2 (bientôt 4.0) • Apparu en 2004 Ruby on Rails
  5. Projet : MyNotes $ rails new MyNotes • Créer un

    nouveau projet $ cd MyNotes $ rails server • Démarrer le serveur
  6. $ rails generate scaffold note title content:text invoke active_record create

    db/migrate/20130130171611_create_notes.rb create app/models/note.rb invoke test_unit create test/unit/note_test.rb create test/fixtures/notes.yml invoke resource_route route resources :notes invoke scaffold_controller create app/controllers/notes_controller.rb invoke erb create app/views/notes create app/views/notes/index.html.erb create app/views/notes/edit.html.erb create app/views/notes/show.html.erb create app/views/notes/new.html.erb create app/views/notes/_form.html.erb ... Génération du CRUD
  7. Migration class CreateNotes < ActiveRecord::Migration def change create_table :notes do

    |t| t.string :title t.text :content t.timestamps end end end db/migrate/20130130175117_create_notes.rb $ rake db:migrate
  8. Vue

  9. ERB <p> <b>Title:</b> <%= @note.title %> </p> <p> <b>Content:</b> <%=

    @note.content %> </p> app/views/notes/show.html.erb
  10. Formulaires <%= form_for(@note) do |f| %> <%= f.label :title %>

    <%= f.text_field :title %> <%= f.label :content %> <%= f.text_area :content %> <%= f.submit %> <% end %>
  11. Contrôleur class NotesController < ApplicationController def show @note = Note.find(params[:id])

    end end app/controllers/notes_controller.rb app/views/notes/show.html.erb Request GET /notes/1 <p> <b>Title:</b> <%= @note.title %> </p>
  12. Indexation Twitter NoSQL Paiement en ligne Géolocalisation Parsing Pagination Cache

    Tâches de fonds Upload de fichiers Facebook Authentification Localisation OAuth A/B teste LDAP