11. class PigsController
caches_page :show
def show
@pig = Pig.find(params[:id])
end
def update
@pig = Pig.find(params[:id])
@pig.update_attributes(params[:pig])
expire_page :action => :show
end
end
Sunday, March 22, 2009
12. Standard 1
Page 3000
requests per second
Sunday, March 22, 2009
17. class PigsController
require_login :show
caches_action :show
def show
@pig = Pig.find(params[:id])
end
def update
@pig = Pig.find(params[:id])
@pig.update_attributes(params[:pig])
expire_action :action => :show
end
end
Sunday, March 22, 2009
18. Standard 1
Action 500
Page 3000
requests per second
Sunday, March 22, 2009
32. class BigBadWolf
def self.call(env)
if env[quot;PATH_INFOquot;] =~ /^/threaten/
[
200,
{quot;Content-Typequot; => quot;text/htmlquot;},
quot;Little pig, little pig, let me in!quot;
]
else
[
404,
{quot;Content-Typequot; => quot;text/htmlquot;},
quot;Not Foundquot;
]
end
end
end
Sunday, March 22, 2009
56. class ItemsController < ApplicationController
def index
@user = User.find_by_login(params[:user])
@items = Item.released_on(params[:date])
end
end
Sunday, March 22, 2009
57. class Item < ActiveRecord::Base
has_many :pulls, :dependent => :destroy
named_scope :released_on, lambda { |date|
date ||= Item.maximum(:released_on)
{:conditions => {:released_on => date}, :order => 'name ASC'}
}
def pulled_by?(user)
x = user.nil? ? false : !self.pulls.by_user(user.id).empty?
end
end
Sunday, March 22, 2009
58. <h1>Releases</h1>
<ul>
<% @items.each do |item| %>
<% content_tag_for :li, item do %>
<%= image_tag 'cover.png', :alt => h(item.name), :class => 'cover' %>
<%= image_tag('badge.png', :alt => 'pulling',:class => 'badge')
if item.pulled_by?(@user) %>
<p><%= h item.name %></p>
<% end %>
<% end %>
</ul>
Sunday, March 22, 2009
60. class ItemsController < ApplicationController
caches_page :index
def index
@items = Item.released_on(params[:date]).all
end
end
Sunday, March 22, 2009
61. require(File.dirname(__FILE__) + quot;/../../config/environmentquot;) unless
defined?(Rails)
class PullList
def self.call(env)
if env[quot;PATH_INFOquot;] =~ /^/pulls/
date = '2008-11-05'
user = '1'
[
200,
{quot;Content-Typequot; => quot;application/javascriptquot;},
[Pull.by_user(user).for_date(date).map {|i| i.item_id}.to_json]]
else
[404, {quot;Content-Typequot; => quot;text/htmlquot;}, [quot;Not Foundquot;]]
end
end
end
Sunday, March 22, 2009