Ruby On Rails Presentation Barcamp Antwerp.Key

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    Sinds 3j RoR dev

    daarvoor: PHP, Java, ASP.NET C#, COBOL, HTTP, CSS
    leren developen op het web

    Wat is RoR.. eerst en vooral het Ruby

    Created by Yukihiro Matsumoto, a.k.a. Matz in 1995

    Smalltalk: Full OO, Dynamic typing, reflecting/meta programming

    Phython: easy, natural syntax

    Perl’s Pragamatism: Gezond verstand en realisme aanleggen en praktish gericht zijn ipv theoretish

    ** Principal of Least Surprise
    ** Completely OO
    ** Syntax for programmers

    Dynamic typing => duck typing
    introspection .methods method
    redefine method in same class / redefine methods for an instance
    Multiple inheritance like in c

    A dynamic, object-oriented programming language with:
    •a strong focus on simplicity and productivity
    •an elegant, natural syntax
    •roots in Lisp, Perl, and Smalltalk

    Leesbaar, te verwachten syntax

    5 is obviously a object
    leesbaar, te verwachten syntax

    No need to define the variables of an object
    optional arguments (*args)

    Only in Rails, ook in february

    Reflection! (1.month is afhankelijk van Time.now)

    code blocks!

    True

    nil is an Object
    Class is an Object (word wat ingewikkeld)

    Nu, wat is Rails dan?

    Is een volledig web framework

    - Abstraction (DB, environment)
    - Geen SERVER
    - Convention over Configuration
    - MVC

    Rails gebruikt het MVC pattern.
    Voor die gene die MVC niet kennen:
    Model: Object represenatie van de data en business logic
    View: Presentatie van de data
    Conroller: Het gene er tussenin (haal data op om te displayen, regageert op user actions)

    De folder structuur van een Rails app ziet er zo uit.
    - Controllers
    - Models
    - Views

    helpers voor views the helpen

    ten eerste de Models

    ActiveRecord is de basis klasse van alle DB models in Rails
    - Klass is a table
    - Columns are attributes
    - Rows are instances

    Abstractie van alle database, en db type:
    MySQL, PostgreSQL, SQLite, Oracle, MS SQLServer, and IBM DB2. out of the box

    Dit is hoe een model er kan uit zien

    Het aanmaken van een tabel (een migration) is Database agnostisch.

    ActiveRecord zal automatisch de tabel “posts” vinden (plural van Post) en al de attributen zullen aanwezig zijn als getters/setters

    Free magic:
    id column
    created/updated_at
    counters

    Enkele van de “gratis” methods

    Gratis instance methods

    We kunnen natuurlijk de definitie van het model aanpassen

    Weinig code => veel functionaliteit

    - associations (belongs_to, has_one, has_many, :through, conditions ... )
    - Validations (uniqness, range, presence, :if, custom)
    - named scope (pre defined pieces of queries, condition, order, grouping)

    Deze method calls gebeuren dus vooral in de controllers

    Controllers
    - reageert op de HTTP requests “actions”

    OUt of the box krijgen we

    Out of the box doet deze Klasse al veel voor je

    - Securing een session (encoding the session info)

    - Cross site scripting attacks afweren (session VS post variables)

    - Vertalen van URL’s naar methods in controllers // Routing

    - Als er een AR model niet gevonden word, 404 displayen, of een 500 page waneer er zich een andere excpetion voor doet

    Routing
    - Controller
    - Action
    - Params

    Gedefinieerd in routes file,
    Eigen routes of standaard routes / REST

    REST = Representational_State_Transfer
    CRUD over HTTP
    PUT en DELETE zijn niet supported door Browsers (behalve in JS) en word gemuleerd door de Rails

    HTTP is meer dan GET and POST (WebDAV, CalDAV) verbs

    Zolas je kan zien kan rails bepalen in welk format het moet antwoorden
    HTML, XML, JSON, ICAL, JS gebaseerd op de request

    De view hoeft niet expliciet aangeroepen worden (default) view heeft zelfde naam als action


    Views zijn redelijk simpel
    - Helper methods (link_to)
    - translations t()
    - url/path generators/helpers

    action/name . format . processor

    partials
    layouts

    Helpers zijn er om de view te helpen.
    Ze bevatten stukjes logica die meer dan een regel beslaan,
    zodat de view zelf niet vervuilt word met teveel logica

    Bepaalde stukken logica gaan zich vaak herhalen zowel binnen 1 als in meerdere applicaties
    - Login validatie,
    - Rating van Items in de database (stars)
    - Comments logic
    - etc...

    Weinig woorden en veel daden

    Dankzij convention over configuration:
    - Bijna lege models (mapping en configuratie automatisch)

    Configuration still possible
    - legacy DB, highly custom systems

    Logica dat vaak herhaalt word kan in een module geplaatst worden
    en included worden door objecten die het willen

    acts_as_featurable eigen project

    Laat toe dat Models featured kunnen worden (dmv een feature model)
    Alle logica is in de module
    - association
    - AR methods
    - instance methods

    - Klass methods
    - validations ...

    1 lijntje brengt onmiddelijk een hele reeks code met zich mee

    ActiveRecord zelf is ook aangepast, zodat elk model kan zeggen of het gefeatured kan worden

    Gems en plugins zijn al vooraf geschreven stukken code, liberaries
    Waarom herhalen wat anderen al hebben geschreven?

    commentable: comment system voor de site
    taggable: full tagging system (zijn volledige tables, maar doen zich voor als array in model)
    list: als order belangrijk is
    paginate: limit queries, and pagination voor HTML (AR, AC)
    default: complexe default values (uuid, time based, )

    Ten slotte nog enkele plugins in detail

    Ten slotte

    Authlogic voorziet een volledige authenticatie systeem
    Definieer het User model and you are ready to roll
    - Sessies gedragen zich net als andere modellen
    - Password security is transparant
    - tracken van login times
    - create / confirmed / approved status van account
    - etc...

    Easy file attachment management for ActiveRecord
    - Zet zelf attributen in DB
    - Manage files zelf, methods zoals public_path en local_path
    - Thumbnails automatisch
    - Processors toevoegen (OCR, red eyes...)
    -

    HTML, maar dan compacter

    Dankuwel


    3 Favorites & 1 Event

    Ruby On Rails Presentation Barcamp Antwerp.Key - Presentation Transcript

    1. Ruby on Rails Introduction Sunday, March 22, 2009
    2. Ruby Sunday, March 22, 2009
    3. Ruby successfully combines Smalltalk's conceptual elegance, Phython's ease of use and learning, and Perl's pragmatism Sunday, March 22, 2009
    4. Ruby is Highly Dynamic • Uses dynamic typing (vs. static) • Full support for introspection • Support for method redefinition • Create your own domain-specific languages • Modules vs. multiple inheritance • method_missing, etc... Sunday, March 22, 2009
    5. puts \"upper\".upcase Sunday, March 22, 2009
    6. 5.times do   puts \"Ruby Rocks!\" end Sunday, March 22, 2009
    7. class Greeter   def initialize(greeting)     @greeting = greeting   end     def salute(name = \"you\")     puts \"#{@greeting} #{name}!\"   end end Sunday, March 22, 2009
    8. next_month = Time.now + 1.month Sunday, March 22, 2009
    9. def thrice   yield(1)   yield(2)   yield(3) end   # Output \"Blocks are cool!\" three times with the count thrice do |i|   puts \"#{i}: Blocks are cool!\" end Sunday, March 22, 2009
    10. nil.is_a? Object Class.is_a? Object Sunday, March 22, 2009
    11. Rails Sunday, March 22, 2009
    12. MVC Sunday, March 22, 2009
    13. Sunday, March 22, 2009
    14. ActiveRecord Models Sunday, March 22, 2009
    15. Sunday, March 22, 2009
    16. Post.find(3) Post.find(1..10, :order => ‘title’) Post.first Post.all Post.count Post.create(:title => ‘Foobar’) Post.find_by_title(‘Foobar’) Post.destroy(5) Sunday, March 22, 2009
    17. post = Post.find(27) post.name post.body post.created_at post.title = ‘dance’ post.save post.destroy Sunday, March 22, 2009
    18. Post.without_title.first Post.first.user Sunday, March 22, 2009
    19. ActionController Controller Sunday, March 22, 2009
    20. • Routing • Session handeling, security • Request Forgery protection • Exception Handling Sunday, March 22, 2009
    21. #GET http://localhost:3000/posts/7/edit Sunday, March 22, 2009
    22. #GET http://localhost:3000/posts/7/edit PostController Sunday, March 22, 2009
    23. #GET http://localhost:3000/posts/7/edit PostController action: edit Sunday, March 22, 2009
    24. #GET http://localhost:3000/posts/7/edit PostController params[:id] = 7 action: edit Sunday, March 22, 2009
    25. REST #GET /posts #GET /posts/1 #GET /post/1/edit #GET /post/new #POST /posts #PUT /posts/1 #DELETE /posts/1 Sunday, March 22, 2009
    26. Sunday, March 22, 2009
    27. ActionView Views Sunday, March 22, 2009
    28. View Sunday, March 22, 2009
    29. Helper Sunday, March 22, 2009
    30. DRY Don’t repeat yourself Sunday, March 22, 2009
    31. Modularity /lib Sunday, March 22, 2009
    32. Sunday, March 22, 2009
    33. class Video < ActiveRecord::Base   acts_as_featured end User.featurable? # => false Video.featurable? # => true Video.first.feature! Sunday, March 22, 2009
    34. Gems and Plugins Sunday, March 22, 2009
    35. acts_as_commentable acts_as_taggable acts_as_list will_paginate default_value_for Sunday, March 22, 2009
    36. Authlogic Sunday, March 22, 2009
    37. Paperclip Sunday, March 22, 2009
    38. HAML Sunday, March 22, 2009
    39. Thx! Give me Q, I’ll give you A. Sunday, March 22, 2009

    + Bert GoethalsBert Goethals, 7 months ago

    custom

    798 views, 3 favs, 0 embeds more stats

    More info about this document

    CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

    Go to text version

    • Total Views 798
      • 798 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 14
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events