Lehmanns Rails Erweitern

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

    Favorites, Groups & Events

    Lehmanns Rails Erweitern - Presentation Transcript

    1. Ruby on Rails Erweitern Ramon Wartala - Jan Krutisch 9. Juli 2007 - Lehmanns Fachbuchhandlung, Hamburg
    2. Wer wir sind • Jan Krutisch und Ramon Wartala • Ehemalige Kollegen • Gründer der deutschen Rails-UG • Autoren von \"Webanwendungen mit Ruby on Rails\", Addison-Wesley
    3. Wer wir sind • Jan Krutisch und Ramon Wartala • Ehemalige Kollegen • Gründer der deutschen Rails-UG • Autoren von \"Webanwendungen mit Ruby on Rails\", Addison-Wesley
    4. Ramon Wartala • Dipl.-Inform. • IT-Leiter bei Orangemedia GmbH • Einer der führenden Online-Vermarkter • Autor zahlreicher Artikel und Tagungsbeiträge rund um Softwareentwicklung
    5. Jan Krutisch • Dipl.-Ing. (FH) Umwelttechnik • Entwicklungsleiter für Rails-Projekte bei mindmatters (www.mindmatters.de) • artdoxa.com / familylounge.de • Jahrelange Erfahrung als Programmierer im Webbereich insbesondere in Java und PHP
    6. Ruby on Rails Historie • Juli 2004, David Heinemeier Hansson veröffentlicht Ruby on Rails als quelloffenes Framework für dir Erstellung von Web Applikationen mit Ruby • Version 1.0 im Dezember 2005 • Version 1.2 im Januar 2007
    7. Ruby on Rails Grundlagen
    8. Ruby
    9. • Moderne Skriptsprache • Anleihen aus Perl, Python, Smalltalk, ... • Alles ist ein Objekt: 5.days.from_now • Starke Introspektion (aka Reflection) • Schwache Typisierung • Closures, Blocks, Iteratoren, etc.
    10. def tausch(x,y) [y, x] end x,y = tausch 1,2 => x=2, y=1
    11. def tausch(x,y) t kgabewer iter Rüc Impliz [y, x] end x,y = tausch 1,2 => x=2, y=1
    12. def tausch(x,y) t kgabewer iter Rüc Impliz [y, x] end weisung ache Zu Mehrf x,y = tausch 1,2 => x=2, y=1
    13. def tausch(x,y) t kgabewer iter Rüc Impliz [y, x] end weisung ache Zu Mehrf on aucht sch Wer br n Klammer x,y = tausch 1,2 => x=2, y=1
    14. Rails
    15. • ModelViewController-Architektur • Convention over Configuration • Don't Repeat Yourself • Unterstützt die Testgetriebene Entwicklung • Unterstützt agile Methoden • Unterstützt Web2.0-Techniken (Ajax etc.)
    16. Das Versprechen von Rails • Sehr viel schnellere Entwicklung durch: • Sehr viel weniger \"Glue code\" • Konzentrierung auf Geschäftslogik • Mehr Spaß am Entwickeln • Höhere Produktivität
    17. Nachteile von Rails • Ruby ist nicht sehr performant • Rails ist nicht sehr performant • Kein „Allgemeinwissen“ • (Noch) keine \"sichere Wahl\" für Entscheider
    18. Die Komponenten • ActiveRecord: Objekt-relationaler Mapper • ActionPack • ActionView • ActionController • ActiveSupport • ActionMailer
    19. Code!
    20. Model class Book < ActiveRecord::Base end
    21. Model Book.find :all Book.find :first, :conditions => [\"isbn = ?\", @isbn] @book = Book.find_by_isbn(@isbn) @book.title = \"Ruby Cookbook\" @book.save @book.destroy
    22. Model mit Beziehungen class Book < ActiveRecord::Base belongs_to :library end class Library < ActiveRecord::Base has_many :books end
    23. Model mit Beziehungen @library = @book.library @books = @library.books @book = @library.books.find_by_isbn @isbn @library << @book @book.library = @library
    24. Model mit Validierungen class Book < ActiveRecord::Base validates_presence_of :title validates_uniqueness_of :isbn end
    25. Model mit Validierungen @book = Book.new @book.save # => false @errors = @book.errors
    26. Controller class BooksController < ApplicationController def index @books = Book.find(:all) end end
    27. View (HTML) <ul> <% for book in @books %> <li><%=h book.title %></li> <% end %> </ul>
    28. View (XML) xml.instruct! :xml, :version=>\"1.0\" xml.bookfeed do for book in @book xml.book do xml.title(book.title) end end end
    29. Weitere Features
    30. Syntaktischer Zucker • belongs_to :library • has_many :books • books_path • book_path(@book)
    31. Tests • Basiert auf Test::Unit • Unit-Tests (Auf Modellebene) • Funktionale Tests (Auf Controllerebene) • Integrationstests (Auf Applikationsebene) • Testausführung automatisiert über Rake
    32. Ajax etc. • prototype.js • script.aculo.us • Helper • rjs-Templates
    33. Helper • Textformatierung (Textile / Markdown) excerpt(text, 'foo') => '...und foo ging...' • Datums-Formatierungen • Datums-Formular-Helper • ...
    34. RESTful • URL = Resource • GET / POST / PUT / DELETE • Klare Architektur • Viele kleine Controller mit wenig Actions
    35. Rails erweitern
    36. Rails erweitern Durch: • rake-Tasks • Mixins • Generatoren • RubyGems • Plugins
    37. Plugins • Erweitern der Rails-Basisklassen • Metaprogrammierung! • Überschreiben, Ergänzen (Mixins) • Eigene Generatoren • Eigene Rake-Tasks
    38. Plugin-Skript • ruby scripts/plugin • discover • source / unsource / sources • list • install / update • remove
    39. Beispiel: acts_as_ferret class Question < ActiveRecord::Base acts_as_ferret :fields => [:title, :text] end Question.find_by_contents('foo')
    40. Model-Plugins • acts_as_state_machine • acts_as_taggable • acts_as_versioned • acts_as_translatable • attachment_fu • acts_as_rateable
    41. Authentifizierung • acts_as_authenticated • authorization • restful_authentication • openid_authentication
    42. Tests • selenium_on_rails • rspec (Behaviour Driven Development) • rcov (Test coverage) • ...
    43. Sonstiges • Streamlined • HOBO • und >400 mehr • http://www.agilewebdevelopment.com/
    44. Eigene Erweiterungen
    45. Eigene Plugins • Funktionalität bestimmen • Plugin-Generator anwerfen • Funktionalität implementieren
    46. Eigene Plugins • acts_as_amazon_book • ruby script/generate plugin acts_as_amazon_book
    47. Eigene Plugins • acts_as_amazon_book • ruby script/generate plugin acts_as_amazon_book
    48. Plugin Anatomie vendor\\plugins\\acts_as_amazon_book init.rb install.rb uninstall.rb vendor\\plugins\\acts_as_amazon\\lib acts_as_amazon_book.rb vendor\\plugin\\acts_as_amazon\\tasks
    49. acts_as_amazon_book.rb
    50. Plugin-Nutzung
    51. Eigene Generatoren • Rails Generatoren in lib\\rails_generator\\generators \\components • Eigene Generatorn in lib \\generators
    52. Eigene Generatoren • Generatoren sind in Rails an vielen Stellen • Eigener Scaffolder Generator wii_scaffolder • Rails scaffolder als Ausgangspunkt
    53. Generator-Anatomie • Jeder Generator erbt von Rails::Generator::Base bzw. Rails::Generator::NamedBase • Regeln zur Erstellung / Anpassung von Dateien / Templates • Implementierung der Methode manifest
    54. Generator-Anatomie record do |m| m.file(…) m.directory(…) … end
    55. Generator-Anatomie
    56. wii_scaffold anwenden • ruby script/generate wii_scaffolder Book books list • „Erzeuge mir mit Hilfe des wii_scaffold- Generators ein Modell Book mit einem Controller books und einer Action list“
    57. wii_scaffold anwenden Erzeugte Dateien: app/model/book.rb public/stylesheets/wii_scaffold.css app/views/book/list.rhtml app/controllers/books_controller.rb app/views/layouts/books.rhtml
    58. wii_scaffold anwenden
    59. Erweiterung verteilen • Code und zusätzliche Dateien verteilen • RubyGems als standardisiertes Distributionswerkzeug • Plugins auch direkt über SVN installierbar ruby script/plugin install \\ http://svn.meinsubversion.com/mein/plugin
    60. RubyGem • Ausgangspunkt jeder Gem ist die Datei .gemspec • Ruby-basierte Spezifikation der zu „verpackenden“ Erweiterung
    61. RubyGem • gem build acts_as_amazon_book.gemspec • => acts_as_amazon_book-0.0.1.gem • gem install acts_as_amazon_book-0.0.1.gem • gem server
    62. RubyGem • gem build acts_as_amazon_book.gemspec • => acts_as_amazon_book-0.0.1.gem • gem install acts_as_amazon_book-0.0.1.gem • gem server
    63. Danke Fragen? • http://www.rubyonrails.org • http://www.rubyonrails-ug.de • http://www.railsjobs.de/

    + jan_mindmattersjan_mindmatters, 3 years ago

    custom

    2153 views, 0 favs, 1 embeds more stats

    Slides of a presentation on Rails and extending Rai more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 2153
      • 2102 on SlideShare
      • 51 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 37
    Most viewed embeds
    • 51 views on http://localhost3000.de

    more

    All embeds
    • 51 views on http://localhost3000.de

    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