Screencast: Rails 3 mit Rack

Rack ist die neue Middleware, die in Version 3 einzug in Rails gefunden hat. Mit der Hilfe Rack können Rails-Applikationen neben z.B. Filter, Caches auch um andere Web-Applikationen erweitert bzw. ergänzt werden. Ryan zeigt diese Woche wie Sinatra für Redirects etc. eingesetzt werden kann.

 

Download:

Download(12.1 MB, 8:48)
Alternativer Download für iPod & Apple TV(12 MB, 8:48)

 

Resourcen:

 

Quellcode:

# routes.rb
root :to => "home#index"
root :to => HomeController.action(:index)
root :to => HomeApp

match "/about" => redirect("/aboutus")
match "/aboutus" => "info#about"

resources :products
match "/p/:id" => redirect("/products/%{id}")

match "/processes" => ProcessesApp.action(:index)

# Gemfile
gem "sinatra"

# lib/home_app.rb
class HomeApp < Sinatra::Base
  get "/" do
    "Hello from Sinatra!"
  end
end

# lib/processes_app.rb
class ProcessesApp < ActionController::Metal
  include ActionController::Rendering

  append_view_path "#{Rails.root}/app/views"

  def index
    @processes = `ps -axcr -o "pid,pcpu,pmem,time,comm"`
    render
  end
end
<!-- app/views/processes_app/index.html.erb -->
<h1>Processes</h1>
<pre><%= @processes %></pre>

Eingestellt am 12.07.2010 um 11:47

Kategorie: Tutorials

Be Sociable, Share!

Kommentare für diesen Artikel wurden geschlossen.

Suchen auf rubyonrails.de

Aktuelle Rails Version + Abhängigkeiten:

Gem rails-3.0.0
actionmailer (= 3.0.0, runtime)
actionpack (= 3.0.0, runtime)
activerecord (= 3.0.0, runtime)
activeresource (= 3.0.0, runtime)
activesupport (= 3.0.0, runtime)
bundler (~> 1.0.0, runtime)
railties (= 3.0.0, runtime)

Rails auf Rubyforge
Rails auf Github