25.2 rake 24.3 Active Resources
edit store.ru
require 'rubygems'
require 'bundler/setup'
require './app/store'
use Rack::ShowExceptions
map '/store' do
run StoreApp.new
end
edit app/store.rb
require 'builder'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'db/development.sqlite3')
class Product < ActiveRecord::Base
end
class StoreApp
def call(env)
x = Builder::XmlMarkup.new :indent=>2
x.declare! :DOCTYPE, :html
x.html do
x.head do
x.title 'Pragmatic Bookshelf'
end
x.body do
x.h1 'Pragmatic Bookshelf'
Product.all.each do |product|
x.h2 product.title
x << " #{product.description}\n"
x.p product.price
end
end
end
response = Rack::Response.new(x.target!)
response['Content-Type'] = 'text/html'
response.finish
end
end
edit config/routes.rb
require './app/store'
Depot::Application.routes.draw do
match 'catalog' => StoreApp.new
get 'admin' => 'admin#index'
controller :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
resources :users
resources :products do
get :who_bought, :on => :member
end
scope '(:locale)' do
resources :orders do
resources :line_items
end
resources :line_items
resources :carts
root :to => "store#index", :as => 'store'
end
end
get /catalog
CoffeeScript is JavaScript done right. It provides all of JavaScript's functionality wrapped in a cleaner, more succinct syntax. In the first book on this exciting new language, CoffeeScript guru Trevor Burnham shows you how to hold onto all the power and flexibility of JavaScript while writing clearer, cleaner, and safer code.
31.0
Ruby is the fastest growing and most exciting dynamic language out there. If you need to get working programs delivered fast, you should add Ruby to your toolbox.
49.95
Rails Test Prescriptions is a comprehensive guide to testing Rails applications, covering Test-Driven Development from both a theoretical perspective (why to test) and from a practical perspective (how to test effectively). It covers the core Rails testing tools and procedures for Rails 2 and Rails 3, and introduces popular add-ons, including Cucumber, Shoulda, Machinist, Mocha, and Rcov.
34.95