SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Ruby on Rails
                             Introduction




Sunday, March 22, 2009
Ruby



Sunday, March 22, 2009
Ruby successfully
                     combines Smalltalk's
                     conceptual elegance,
                     Phython's ease of use
                    and learning, and Perl's
                          pragmatism
Sunday, March 22, 2009
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
puts quot;upperquot;.upcase




Sunday, March 22, 2009
5.times do
                  puts quot;Ruby Rocks!quot;
                end




Sunday, March 22, 2009
class Greeter
   def initialize(greeting)
     @greeting = greeting
   end
  
   def salute(name = quot;youquot;)
     puts quot;#{@greeting} #{name}!quot;
   end
 end

Sunday, March 22, 2009
next_month = Time.now +
                1.month




Sunday, March 22, 2009
def thrice
   yield(1)
   yield(2)
   yield(3)
 end
  
 # Output quot;Blocks are cool!quot; three
 times with the count
 thrice do |i|
   puts quot;#{i}: Blocks are cool!quot;
 end
Sunday, March 22, 2009
nil.is_a? Object
                Class.is_a? Object




Sunday, March 22, 2009
Rails



Sunday, March 22, 2009
MVC




Sunday, March 22, 2009
Sunday, March 22, 2009
ActiveRecord
                             Models




Sunday, March 22, 2009
Sunday, March 22, 2009
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
post = Post.find(27)

                                post.name
                                post.body
                            post.created_at
                         post.title = ‘dance’
                                post.save
                              post.destroy



Sunday, March 22, 2009
Post.without_title.first
                              Post.first.user




Sunday, March 22, 2009
ActionController
                               Controller




Sunday, March 22, 2009
• Routing
                    • Session handeling, security
                    • Request Forgery protection
                    • Exception Handling


Sunday, March 22, 2009
#GET http://localhost:3000/posts/7/edit




Sunday, March 22, 2009
#GET http://localhost:3000/posts/7/edit




        PostController




Sunday, March 22, 2009
#GET http://localhost:3000/posts/7/edit




        PostController                                    action: edit




Sunday, March 22, 2009
#GET http://localhost:3000/posts/7/edit




        PostController              params[:id] = 7       action: edit




Sunday, March 22, 2009
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
Sunday, March 22, 2009
ActionView
                             Views




Sunday, March 22, 2009
View




Sunday, March 22, 2009
Helper




Sunday, March 22, 2009
DRY
                         Don’t repeat yourself




Sunday, March 22, 2009
Modularity
                             /lib




Sunday, March 22, 2009
Sunday, March 22, 2009
class Video < ActiveRecord::Base
   acts_as_featured
 end

 User.featurable? # => false
 Video.featurable? # => true
 Video.first.feature!



Sunday, March 22, 2009
Gems and Plugins



Sunday, March 22, 2009
acts_as_commentable
                        acts_as_taggable
                           acts_as_list
                          will_paginate
                       default_value_for

Sunday, March 22, 2009
Authlogic




Sunday, March 22, 2009
Paperclip




Sunday, March 22, 2009
HAML




Sunday, March 22, 2009
Thx!
                         Give me Q, I’ll give you A.




Sunday, March 22, 2009

Weitere ähnliche Inhalte

Ähnlich wie Ruby On Rails Presentation Barcamp Antwerp.Key

Internationalization of your homepage
Internationalization of your homepageInternationalization of your homepage
Internationalization of your homepage
gutskun
 
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 20092009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
Caue Guerra
 
Scaling with Postgres
Scaling with PostgresScaling with Postgres
Scaling with Postgres
elliando dias
 

Ähnlich wie Ruby On Rails Presentation Barcamp Antwerp.Key (20)

Carrington CMS Theme Framework for WordPress
Carrington CMS Theme Framework for WordPressCarrington CMS Theme Framework for WordPress
Carrington CMS Theme Framework for WordPress
 
Internationalization of your homepage
Internationalization of your homepageInternationalization of your homepage
Internationalization of your homepage
 
The Craftsman Developer In An Agile World
The Craftsman Developer In An Agile WorldThe Craftsman Developer In An Agile World
The Craftsman Developer In An Agile World
 
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 20092009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
 
Realtime 3D on the web - a toy or a useful tool?
Realtime 3D on the web - a toy or a useful tool?Realtime 3D on the web - a toy or a useful tool?
Realtime 3D on the web - a toy or a useful tool?
 
Mozilla - Poetry & Pragmatics (Eliberatica09)
Mozilla - Poetry & Pragmatics (Eliberatica09)Mozilla - Poetry & Pragmatics (Eliberatica09)
Mozilla - Poetry & Pragmatics (Eliberatica09)
 
Devia Podcasting As An Educational Tool Barcamp Antwerp
Devia Podcasting As An Educational Tool Barcamp AntwerpDevia Podcasting As An Educational Tool Barcamp Antwerp
Devia Podcasting As An Educational Tool Barcamp Antwerp
 
Django, Pinax, and Humble Pie
Django, Pinax, and Humble PieDjango, Pinax, and Humble Pie
Django, Pinax, and Humble Pie
 
Serving The Next Billion
Serving The Next BillionServing The Next Billion
Serving The Next Billion
 
Ruby AST Tools
Ruby AST ToolsRuby AST Tools
Ruby AST Tools
 
RefreshPhilly Presentation February 09
RefreshPhilly Presentation February 09RefreshPhilly Presentation February 09
RefreshPhilly Presentation February 09
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
 
Scaling with Postgres
Scaling with PostgresScaling with Postgres
Scaling with Postgres
 
Promiscuous Drupal
Promiscuous DrupalPromiscuous Drupal
Promiscuous Drupal
 
Intro To Ruby
Intro To RubyIntro To Ruby
Intro To Ruby
 
Background Processing in Ruby on Rails
Background Processing in Ruby on RailsBackground Processing in Ruby on Rails
Background Processing in Ruby on Rails
 
Semcomp de São Carlos
Semcomp de São CarlosSemcomp de São Carlos
Semcomp de São Carlos
 
All The Little Pieces
All The Little PiecesAll The Little Pieces
All The Little Pieces
 
Plugin Testing
Plugin TestingPlugin Testing
Plugin Testing
 
2D Video Games with MacRuby
2D Video Games with MacRuby2D Video Games with MacRuby
2D Video Games with MacRuby
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Ruby On Rails Presentation Barcamp Antwerp.Key

Hinweis der Redaktion

  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
  2. Created by Yukihiro Matsumoto, a.k.a. Matz in 1995
  3. Smalltalk: Full OO, Dynamic typing, reflecting/meta programming Phython: easy, natural syntax Perl&#x2019;s Pragamatism: Gezond verstand en realisme aanleggen en praktish gericht zijn ipv theoretish ** Principal of Least Surprise ** Completely OO ** Syntax for programmers
  4. 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: &#x2022;a strong focus on simplicity and productivity &#x2022;an elegant, natural syntax &#x2022;roots in Lisp, Perl, and Smalltalk
  5. Leesbaar, te verwachten syntax
  6. 5 is obviously a object leesbaar, te verwachten syntax
  7. No need to define the variables of an object optional arguments (*args)
  8. Only in Rails, ook in february Reflection! (1.month is afhankelijk van Time.now)
  9. code blocks!
  10. True nil is an Object Class is an Object (word wat ingewikkeld) Nu, wat is Rails dan?
  11. Is een volledig web framework - Abstraction (DB, environment) - Geen SERVER - Convention over Configuration - MVC
  12. 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)
  13. De folder structuur van een Rails app ziet er zo uit. - Controllers - Models - Views helpers voor views the helpen ten eerste de Models
  14. 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
  15. Dit is hoe een model er kan uit zien Het aanmaken van een tabel (een migration) is Database agnostisch. ActiveRecord zal automatisch de tabel &#x201C;posts&#x201D; vinden (plural van Post) en al de attributen zullen aanwezig zijn als getters/setters Free magic: id column created/updated_at counters
  16. Enkele van de &#x201C;gratis&#x201D; methods
  17. Gratis instance methods
  18. 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
  19. Controllers - reageert op de HTTP requests &#x201C;actions&#x201D; OUt of the box krijgen we
  20. 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&#x2019;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
  21. Routing - Controller - Action - Params Gedefinieerd in routes file, Eigen routes of standaard routes / REST
  22. 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
  23. 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
  24. Views zijn redelijk simpel - Helper methods (link_to) - translations t() - url/path generators/helpers action/name . format . processor partials layouts
  25. 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
  26. 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...
  27. Weinig woorden en veel daden Dankzij convention over configuration: - Bijna lege models (mapping en configuratie automatisch) Configuration still possible - legacy DB, highly custom systems
  28. Logica dat vaak herhaalt word kan in een module geplaatst worden en included worden door objecten die het willen
  29. 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 ...
  30. 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
  31. Gems en plugins zijn al vooraf geschreven stukken code, liberaries Waarom herhalen wat anderen al hebben geschreven?
  32. 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
  33. 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...
  34. 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...) -
  35. HTML, maar dan compacter Dankuwel