Rubyund
Ruby on RailsDie neuen Unbekannten in der (Web-)Entwicklung
Beate Paland (http://www.paland.net/)
5.times do
puts “ruby ist cool”.upcase
end
"Hallo sage".delete("a") # Hllo sge
Ruby• objekt-orientierte und dynamische
Programmiersprache
• Einflüsse von Python, Perl and Lisp
• Yukihiro Matsumoto - „Matz“ (1995)
• Prinzip der geringsten Überraschung
class Fixnum def even? self % 2 == 0 end end
Erweiterung zur Laufzeit
puts 3.even? # => falseputs 2.even? # => true
RubyGems
• Paketsystem für Ruby
• vergleichbar mit CPAN (Perl) oder PEAR (php)
• Viele Pakete, z.B. fastercsv, rmagick oder xml-simple
Features• aktuelle Version 1.2.3
• Open Source und kostenlos
• „Don’t repeat yourself” (DRY)
• Convention over Configuration
• DB: MySQL, SQLite, PostgreSQL, Oracle, ...
• Scaffolding
• AJAX
• Unit Tests
• API-Support
• Plugin-Support
MVC
domain.de/:controller/:action, z.B.
domain.de/users/new
URL-Schema
ActionMailerActiveRecord
ActionViewActionController
ActionWebService
class Customer < ActiveRecord::Base
has_one :address
has_many :projects, :order => 'name ASC'
validates_presence_of :name, :maximum => 50, :message => "darf nicht leer sein."
def fullname
firstname + " " + lastname
end
end
Model
Controller
def list @users = User.find(:all)
end
• User.find(:all)
• User.find(:first, :conditions => [“user = ? AND password = ?”], user, pass)
....
<ul>
<% for user in @users %>
<li><%= link_to user.name, :action => 'show', :id => user.id %> ( <%= link_to "ändern", :action => 'edit', :id => user.id %>)</li>
<% end %>
</ul>
...
View
Entwicklung
• Mac, Linux, Windows
• Migration
• Webserver:
• Mongrel
• Lighttpd
• FastCGI mit Apache oder Lighttpd
• Webrick
Web Services
• SOAP und XML-RPC
• REST (Representational State Transfer)
• HTTP-Methoden GET, PUT, POST und DELETE
def list @people = Person.find(:all)
respond_to do |wants| wants.html wants.xml { render :xml => @people.to_xml } endend
Vorteile eines Frameworks
• Schnellere Einarbeitung in bestehende Projekte
• Mehr Sicherheit, z.B. durch SQL-Escaping
• häufig gebrauchte Funktionen bereits enthalten
• ...
Warum Rails?
Frameworks in anderen Sprachen:
• Python: TurboGears, Django
• PHP: Symfony, Cake, ...
• Perl: Catalyst
• Java...
Getting Started
• Software:http://rubyonrails.com/images/books/awdr2.gif
• InstantRails/Locomotive/zu Fuß
• IDE: RadRails/TextMate
• Bücher (Auswahl)
• „Agile Web Development with Rails“ (en)
• „Rapid Web Development mit Ruby on Rails“ (de)
• Mailingliste en/de
Top Related