if [ -z "$KEEPDB" ]; then
echo "Reloading the database"
{
# lots o’ rake tasks
} >&3 2>&1
fi
Slide 58
Slide 58 text
concerns
everywhere
Slide 59
Slide 59 text
sharing code is hard
Slide 60
Slide 60 text
use a concern!
Slide 61
Slide 61 text
module YourConcern
extend ActiveSupport::Concern
included do
# class methods here
end
# instance methods here
end
Slide 62
Slide 62 text
module Ajax
extend ActiveSupport::Concern
included do
before_filter :set_ajax_cookies
end
private
def set_ajax_cookies
Slide 63
Slide 63 text
models
trashing
searching
buckets
permissions
Slide 64
Slide 64 text
controllers
rendering assets
authorization
authentication
current person, account
Slide 65
Slide 65 text
group alike methods
Slide 66
Slide 66 text
class ApplicationController
include CurrentAccount
include CurrentPerson
include ExceptionNotification
include Ajax
include Mobile
include EnsureCompatibleBrowser
include WrongContentTypeFallback
class Api::DocumentsController <
Api::BaseController
def update
@document.update_attributes!
document_params
render :show
end
def document_params
params.required(:document).
permit(:title, :content)
end
end
Slide 129
Slide 129 text
class Api::DocumentsController <
Api::BaseController
def update
@document.update_attributes!
document_params
render :show
end
def document_params
params.required(:document).
permit(:title, :content)
end
end
Slide 130
Slide 130 text
class Api::DocumentsController <
Api::BaseController
def update
@document.update_attributes!
document_params
render :show
end
def document_params
params.required(:document).
permit(:title, :content)
end
end
Slide 131
Slide 131 text
class Api::DocumentsController <
Api::BaseController
def update
@document.update_attributes!
document_params
render :show
end
def document_params
params.required(:document).
permit(:title, :content)
end
end
Slide 132
Slide 132 text
why not attr_accessible?
controller, not a model problem
can still share via concerns
easier to return error, status codes
Slide 133
Slide 133 text
HTTP 204 No Content
http://httpstatus.es/204
Use on create, destroy actions!
Slide 134
Slide 134 text
can’t read
headers from
HTTP 204
http://bugs.jquery.com/ticket/1450
Slide 135
Slide 135 text
No content
Slide 136
Slide 136 text
No content
Slide 137
Slide 137 text
logging
is worth it
Slide 138
Slide 138 text
No content
Slide 139
Slide 139 text
log EVERYTHING
unique ID per request
account ID for log splitting
controller, actions on each SQL query
Slide 140
Slide 140 text
ActiveSupport::TaggedLogger
new in Rails 3.2!
Slide 141
Slide 141 text
YourApp::Application.configure do
config.log_tags = [:uuid]
end
[71ba53fd717c67a6677a058f4a5acdf4]
Processing by ProjectsController#index
as HTML
Slide 142
Slide 142 text
BCX::Application.configure do
config.log_tags = [
-> request {
request.env['bcx.account.queenbee_id']
}
]
end
Slide 143
Slide 143 text
That just happened.
<3 Ruby 1.9 lambdas
Extremely configurable logging
Use Rack’s environment for sharing data
module Rails::Rack::Logger
# if tags are defined...
Rails.logger.tagged(compute_tags(env)) {
call_app(env)
}
# else
call_app(env)
Slide 146
Slide 146 text
def compute_tags(env)
request = ActionDispatch::Request.new(env)
@tags.collect do |tag|
case tag
when Proc
tag.call(request)
when Symbol
request.send(tag)
else
tag
end
end
end
Slide 147
Slide 147 text
def compute_tags(env)
request = ActionDispatch::Request.new(env)
@tags.collect do |tag|
case tag
when Proc
tag.call(request)
when Symbol
request.send(tag)
else
tag
end
end
end
Slide 148
Slide 148 text
def compute_tags(env)
request = ActionDispatch::Request.new(env)
@tags.collect do |tag|
case tag
when Proc
tag.call(request)
when Symbol
request.send(tag)
else
tag
end
end
end
Slide 149
Slide 149 text
def compute_tags(env)
request = ActionDispatch::Request.new(env)
@tags.collect do |tag|
case tag
when Proc
tag.call(request)
when Symbol
request.send(tag)
else
tag
end
end
end
Slide 150
Slide 150 text
def compute_tags(env)
request = ActionDispatch::Request.new(env)
@tags.collect do |tag|
case tag
when Proc
tag.call(request)
when Symbol
request.send(tag)
else
tag
end
end
end
Slide 151
Slide 151 text
No content
Slide 152
Slide 152 text
marginalia
http://github.com/37signals/marginalia
Slide 153
Slide 153 text
Account Load (0.3ms) SELECT `accounts`.*
FROM `accounts`
WHERE `accounts`.`queenbee_id` = 1234567890
LIMIT 1
/*application:BCX,
controller:project_imports,action:show*/
Slide 154
Slide 154 text
# in your Gemfile
gem 'query_comments'
# in an initializer
Marginalia.application_name = "BCX"
Slide 155
Slide 155 text
MORE logging?
Know where slow queries came from
Immediately identify web or job query
MySQL, sqlite, maybe Postgres now?