Agile Web Development with Rails, Edition 4
25.1 rack
22 Caching
24.3 Active Resources
<36.0> expected but was
<Using rake (10.0.2) >.
<0> expected to be
>=
<1>.
Traceback:
/home/rubys/git/awdwr/edition4/checkdepot.rb:361:in `block in <class:DepotTest>'
bundle exec /home/rubys/git/rails/railties/bin/rails new depot_client --skip-bundle --dev
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/images/rails.png
create app/assets/javascripts/application.js
create app/assets/stylesheets/application.css
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/views/layouts/application.html.erb
create app/mailers/.keep
create app/models/.keep
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/locale.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/initializers/wrap_parameters.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.keep
create lib/assets
create lib/assets/.keep
create log
create log/.keep
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create script
create script/rails
create test/fixtures
create test/fixtures/.keep
create test/controllers
create test/controllers/.keep
create test/mailers
create test/mailers/.keep
create test/models
create test/models/.keep
create test/helpers
create test/helpers/.keep
create test/integration
create test/integration/.keep
create test/performance/browsing_test.rb
create test/test_helper.rb
create tmp/cache
create tmp/cache/assets
create vendor/assets/javascripts
create vendor/assets/javascripts/.keep
create vendor/assets/stylesheets
create vendor/assets/stylesheets/.keep
bundle install
Using rake (10.0.2)
Using i18n (0.6.1)
Using minitest (4.3.3)
Using multi_json (1.4.0)
Using tzinfo (0.3.35)
Using activesupport (4.0.0.beta)
Using builder (3.1.4)
Using erubis (2.7.0)
Using journey (2.0.0.20120723141804)
Using rack (1.4.1)
Using rack-test (0.6.2)
Using actionpack (4.0.0.beta)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.12)
Using mail (2.5.3)
Using actionmailer (4.0.0.beta)
Using activemodel (4.0.0.beta)
Using activerecord-deprecated_finders (0.0.1)
Using arel (3.0.2.20120819075748)
Using activerecord (4.0.0.beta)
Using activeresource (4.0.0.beta)
Using bundler (1.2.3)
Using coffee-script-source (1.4.0)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using json (1.7.5)
Using rdoc (3.12)
Using thor (0.16.0)
Using railties (4.0.0.beta)
Using coffee-rails (4.0.0.beta)
Using hike (1.2.1)
Using jquery-rails (2.1.4)
Using tilt (1.3.3)
Using sprockets (2.8.1)
Using sprockets-rails (2.0.0.rc1)
Using rails (4.0.0.beta)
Using sass (3.2.3)
Using sass-rails (4.0.0.beta)
Using sqlite3 (1.3.6)
Using turbolinks (0.6.1)
Using uglifier (1.3.0)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Add in the activeresource gem
edit Gemfile
# source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem "activeresource", :require => 'active_resource', :path => "/home/rubys/git/activeresource"
gem "activerecord-deprecated_finders", :path => "/home/rubys/git/activerecord-deprecated_finders"
gem "arel", :path => "/home/rubys/git/arel"
gem "journey", :path => "/home/rubys/git/journey"
gem 'rails', :path => "/home/rubys/git/rails" # '4.0.0.beta'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sprockets-rails', :path => "/home/rubys/git/sprockets-rails" # '~> 2.0.0.rc1'
gem 'sass-rails', :path => "/home/rubys/git/sass-rails" # '~> 4.0.0.beta'
gem 'coffee-rails', :path => "/home/rubys/git/coffee-rails" # '~> 4.0.0.beta'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano', group: :development
# To use debugger
# gem 'debugger'
edit app/models/product.rb
class Product < ActiveResource::Base
self.site = 'http://dave:secret@localhost:3000/'
end
echo "Product.find(2).title" | IRBRC=tmp/irbrc rails console
Loading development environment (Rails 4.0.0.beta)
Switch to inspect mode.
>> Product.find(2).title
LoadError: cannot load such file -- rails/observers/active_model/observing
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `block in load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/activeresource/lib/active_resource/observing.rb:1:in `<top (required)>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1541:in `<class:Base>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1537:in `<module:ActiveResource>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:22:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-200/depot_client/app/models/product.rb:1:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `block in load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:421:in `load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:322:in `require_or_load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:461:in `load_missing_constant'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:182:in `const_missing'
from (irb):1
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'>>
edit app/controllers/line_items_controller.rb
def create
@cart = current_cart
if params[:line_item]
# ActiveResource
params[:line_item][:order_id] = params[:order_id]
@line_item = LineItem.new(params[:line_item])
else
# HTML forms
product = Product.find(params[:product_id])
@line_item = @cart.add_product(product.id)
end
@line_item.product = product
respond_to do |format|
if @line_item.save
format.html { redirect_to store_url }
format.js { @current_item = @line_item }
format.json { render json: @line_item,
status: :created, location: @line_item }
else
format.html { render action: "new" }
format.json { render json: @line_item.errors,
status: :unprocessable_entity }
end
end
end
edit config/routes.rb
Depot::Application.routes.draw do
get 'admin' => 'admin#index'
controller :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
get "sessions/create"
get "sessions/destroy"
scope '(:locale)' do
resources :users
resources :orders do
resources :line_items
end
resources :line_items
resources :carts
resources :products do
get :who_bought, on: :member
end
root to: 'store#index', as: 'store', via: :all
end
end
Disable CSRF checking
edit app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_filter :set_i18n_locale_from_params
# ...
before_filter :authorize
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :reset_session
private
def current_cart
Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
cart = Cart.create
session[:cart_id] = cart.id
cart
end
# ...
protected
def authorize
if request.format == Mime::HTML
unless User.find_by_id(session[:user_id])
redirect_to login_url, notice: "Please log in"
end
else
authenticate_or_request_with_http_basic do |username, password|
user = User.find_by_name(username)
user && user.authenticate(password)
end
end
end
def set_i18n_locale_from_params
if params[:locale]
if I18n.available_locales.include?(params[:locale].to_sym)
I18n.locale = params[:locale]
else
flash.now[:notice] =
"#{params[:locale]} translation not available"
logger.error flash.now[:notice]
end
end
end
def default_url_options
{ locale: I18n.locale }
end
end
echo "Product.find(2).title" | IRBRC=tmp/irbrc rails console
Loading development environment (Rails 4.0.0.beta)
Switch to inspect mode.
>> Product.find(2).title
LoadError: cannot load such file -- rails/observers/active_model/observing
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `block in load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/activeresource/lib/active_resource/observing.rb:1:in `<top (required)>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1541:in `<class:Base>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1537:in `<module:ActiveResource>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:22:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-200/depot_client/app/models/product.rb:1:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `block in load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:421:in `load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:322:in `require_or_load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:461:in `load_missing_constant'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:182:in `const_missing'
from (irb):1
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'>>
echo "p = Product.find(2)\\nputs p.price\\np.price = BigDecimal.new(p.price)-5\\np.save" | IRBRC=tmp/irbrc rails console
Loading development environment (Rails 4.0.0.beta)
Switch to inspect mode.
>> p = Product.find(2)
LoadError: cannot load such file -- rails/observers/active_model/observing
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `block in load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/activeresource/lib/active_resource/observing.rb:1:in `<top (required)>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1541:in `<class:Base>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1537:in `<module:ActiveResource>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:22:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-200/depot_client/app/models/product.rb:1:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `block in load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:421:in `load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:322:in `require_or_load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:461:in `load_missing_constant'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:182:in `const_missing'
from (irb):1
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'>> puts p.price
NoMethodError: undefined method `price' for nil:NilClass
from (irb):2
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
>> p.price = BigDecimal.new(p.price)-5
NoMethodError: undefined method `price' for nil:NilClass
from (irb):3
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
>> p.save
NoMethodError: undefined method `save' for nil:NilClass
from (irb):4
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
>>
expire cache
rm -rf /home/rubys/git/awdwr/edition4/work-200/depot/tmp/cache
fetch storefront
get /
Pragmatic Bookshelf
Your Pragmatic Catalog
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.
Programming Ruby 1.9
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.
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.
fetch product (fallback in case storefront is cached)
get /login
Pragmatic Bookshelf
post /login?locale=en
name => dave
password => secret
You are being
redirected .
get http://localhost:3000/admin?locale=en
Pragmatic Bookshelf
Welcome
It's 2012-12-08 09:32:39 -0500
We have 102 orders.
get /products/2
Pragmatic Bookshelf
Title:
CoffeeScript
Description:
<p>
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.
</p>
Image url:
cs.jpg
Price:
36.0
Edit |
Back
edit app/models/order.rb
class Order < ActiveResource::Base
self.site = 'http://dave:secret@localhost:3000/'
end
echo "Order.find(1).name\\nOrder.find(1).line_items\\n" | IRBRC=tmp/irbrc rails console
Loading development environment (Rails 4.0.0.beta)
Switch to inspect mode.
>> Order.find(1).name
LoadError: cannot load such file -- rails/observers/active_model/observing
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `block in load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/activeresource/lib/active_resource/observing.rb:1:in `<top (required)>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1541:in `<class:Base>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1537:in `<module:ActiveResource>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:22:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-200/depot_client/app/models/order.rb:1:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `block in load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:421:in `load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:322:in `require_or_load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:461:in `load_missing_constant'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:182:in `const_missing'
from (irb):1
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'>> Order.find(1).line_items
LoadError: cannot load such file -- rails/observers/active_model/observing
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `block in load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/activeresource/lib/active_resource/observing.rb:1:in `<top (required)>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1541:in `<class:Base>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1537:in `<module:ActiveResource>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:22:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-200/depot_client/app/models/order.rb:1:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `block in load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:421:in `load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:322:in `require_or_load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:461:in `load_missing_constant'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:182:in `const_missing'
from (irb):2
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'>>
edit app/models/line_item.rb
class LineItem < ActiveResource::Base
self.site = 'http://dave:secret@localhost:3000/orders/:order_id'
end
post /logout?locale=en
You are being
redirected .
get http://localhost:3000/en
Pragmatic Bookshelf
Logged out
Your Pragmatic Catalog
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.
Programming Ruby 1.9
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.
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.
echo "LineItem.find(:all, :params => {:order_id=>1})" | IRBRC=tmp/irbrc rails console
Loading development environment (Rails 4.0.0.beta)
Switch to inspect mode.
>> LineItem.find(:all, :params => {:order_id=>1})
LoadError: cannot load such file -- rails/observers/active_model/observing
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `block in load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/activeresource/lib/active_resource/observing.rb:1:in `<top (required)>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1541:in `<class:Base>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1537:in `<module:ActiveResource>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:22:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-200/depot_client/app/models/line_item.rb:1:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `block in load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:421:in `load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:322:in `require_or_load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:461:in `load_missing_constant'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:182:in `const_missing'
from (irb):1
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'>>
get /orders/1/line_items.json
[{"line_item":{"id":10,"product_id":2,"cart_id":null,"created_at":"2012-12-08T14:26:44Z","updated_at":"2012-12-08T14:27:21Z","quantity":1,"price":"36.0","order_id":1}},{"line_item":{"id":11,"product_id":2,"cart_id":null,"created_at":"2012-12-08T14:30:46Z","updated_at":"2012-12-08T14:30:56Z","quantity":2,"price":"36.0","order_id":102}}]
edit app/controllers/line_items_controller.rb
def index
@line_items = LineItem.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @line_items }
format.xml { render xml: @line_items }
end
end
get /orders/1/line_items.xml
<?xml version="1.0" encoding="UTF-8"?>
<line-items type="array">
<line-item>
<id type="integer">10</id>
<product-id type="integer">2</product-id>
<cart-id type="integer" nil="true"/>
<created-at type="dateTime">2012-12-08T14:26:44Z</created-at>
<updated-at type="dateTime">2012-12-08T14:27:21Z</updated-at>
<quantity type="integer">1</quantity>
<price type="decimal">36.0</price>
<order-id type="integer">1</order-id>
</line-item>
<line-item>
<id type="integer">11</id>
<product-id type="integer">2</product-id>
<cart-id type="integer" nil="true"/>
<created-at type="dateTime">2012-12-08T14:30:46Z</created-at>
<updated-at type="dateTime">2012-12-08T14:30:56Z</updated-at>
<quantity type="integer">2</quantity>
<price type="decimal">36.0</price>
<order-id type="integer">102</order-id>
</line-item>
</line-items>
echo "LineItem.format = :xml\\nli = LineItem.find(:all, :params => {:order_id=>1}).first\\nputs li.price\\nli.price *= 0.8\\nli.save" | IRBRC=tmp/irbrc rails console
Loading development environment (Rails 4.0.0.beta)
Switch to inspect mode.
>> LineItem.format = :xml
LoadError: cannot load such file -- rails/observers/active_model/observing
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `block in load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/activeresource/lib/active_resource/observing.rb:1:in `<top (required)>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1541:in `<class:Base>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1537:in `<module:ActiveResource>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:22:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-200/depot_client/app/models/line_item.rb:1:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `block in load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:421:in `load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:322:in `require_or_load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:461:in `load_missing_constant'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:182:in `const_missing'
from (irb):1
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'>> li = LineItem.find(:all, :params => {:order_id=>1}).first
LoadError: cannot load such file -- rails/observers/active_model/observing
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `block in load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/activeresource/lib/active_resource/observing.rb:1:in `<top (required)>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1541:in `<class:Base>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1537:in `<module:ActiveResource>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:22:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-200/depot_client/app/models/line_item.rb:1:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `block in load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:421:in `load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:322:in `require_or_load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:461:in `load_missing_constant'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:182:in `const_missing'
from (irb):2
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'>> puts li.price
NoMethodError: undefined method `price' for nil:NilClass
from (irb):3
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
>> li.price *= 0.8
NoMethodError: undefined method `price' for nil:NilClass
from (irb):4
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
>> li.save
NoMethodError: undefined method `save' for nil:NilClass
from (irb):5
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
>>
echo "li2 = LineItem.new(:order_id=>1, :product_id=>2, :quantity=>1, :price=>0.0)\\nli2.save" | IRBRC=tmp/irbrc rails console
Loading development environment (Rails 4.0.0.beta)
Switch to inspect mode.
>> li2 = LineItem.new(:order_id=>1, :product_id=>2, :quantity=>1, :price=>0.0)
LoadError: cannot load such file -- rails/observers/active_model/observing
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `block in load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:210:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:227:in `require'
from /home/rubys/git/activeresource/lib/active_resource/observing.rb:1:in `<top (required)>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1541:in `<class:Base>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:1537:in `<module:ActiveResource>'
from /home/rubys/git/activeresource/lib/active_resource/base.rb:22:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-200/depot_client/app/models/line_item.rb:1:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:422:in `block in load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:614:in `new_constants_in'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:421:in `load_file'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:322:in `require_or_load'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:461:in `load_missing_constant'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:182:in `const_missing'
from (irb):1
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'>> li2.save
NoMethodError: undefined method `save' for nil:NilClass
from (irb):2
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:78:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands/console.rb:9:in `start'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:71:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
>>
25.1 rack
22 Caching