Before going live, we need legit 404 and 500 error messages. In production mode, the default Sinatra error messages are a little unhelpful:
Sinatra provides two code blocks for handling errors:
not_found doI like having my not found / error templates to be named 404 / 500. Since I am using Haml, I can use the
end
error do
end
404.haml
and 500.haml
templates:not_found doI use :'404' because the
haml :'404'
end
error do
haml :'500'
end
haml
method requires a symbol and :404
is not a valid symbol. After defining the contents of the Haml templates, I have my 404 and 500 error pages.The only other thing that I do tonight is define the kid nicknames document. We share a lot of personal information about our family in the cookbook, but never the actual kids' names (we're even a little vague about birthdays). Maybe we're paranoid, but...
I have a helper that pulls the nicknames from CouchDB:
def kid_nicknamesThose nicknames are then used as part of the "wiki" method:
@@kid_kicknames ||= JSON.parse(RestClient.get("#{_db}/kids"))
end
def wiki(original, convert_textile=true)The seed data for the kids
text = (original || '').dup
#...
text.gsub!(/\[kid:(\w+)\]/m) { |kid| kid_nicknames[$1] }
#...
end
kids
document has been empty. I define it:{And then use my couch_docs gem to load into the CouchDB database:
"___":"our daughter",
"___":"our son",
"___":"the baby"
}
jaynestown% couch-docs load . http://localhost:5984/eeeWith that, I have the nicknames displaying correctly:
That will do for tonight. Tomorrow, I deploy the 404/500 and seed data to beta. Then I can switch beta to be the production site, thus ending my chain.
google 2516
ReplyDeletegoogle 2517
google 2518
google 2519
google 2520
google 2521