Agile Web Development with Rails, Edition 5

25.2 rake 24.3 Managing Dependencies with Bundler

25.1 rack

Restart the server.

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'
Rails.application.routes.draw do
  match 'catalog' => StoreApp.new, via: :all
  get 'admin' => 'admin#index'
  controller :sessions do
    get  'login' => :new
    post 'login' => :create
    delete 'logout' => :destroy
  end
 
  resources :users
  resources :products do
    get :download, on: :member
    get :who_bought, on: :member
  end
 
  scope '(:locale)' do
    resources :orders
    resources :line_items
    resources :carts
    get 'store/index'
    root 'store#index', as: 'store', via: :all
  end
end
get /catalog

Pragmatic Bookshelf

CoffeeScript

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.

36.0

Programming Ruby 1.9 & 2.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

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

25.2 rake 24.3 Managing Dependencies with Bundler