June 23rd, 2009 cschneid
I was using Active Record in a batch application to manipulate some data, and I needed the timezone handling built into the newer versions. But I had a hell of a time trying to figure out how to make it all work.
In plain Rails, it’s simple:
Rails::Initializer.run do |config|
config.time_zone = 'Pacific Time (US & Canada)'
end
But I wasn’t running Rails proper, and didn’t want to pull in the whole Rails boot sequence. So the Rails::Initializer call didn’t work. To do it manually, time zone config turns out it’s a 3 lines of setup calls:
require 'activerecord'
Time.zone = "Pacific Time (US & Canada)"
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = "Pacific Time (US & Canada)"
When you do that, time zone attributes work both going into the database, and coming back out. If you miss the last line, they’ll just not work coming out, which is a damn confusing thing to deal with.
Ohh, and one other thing I ran into when getting this setup is that AR pulls in Active Support, which in turn pulls in Builder (to hack xml support or something). Just watch out for that, you’ll get weird crashes if you don’t have builder installed. Honestly, I just went and commented out the areas of Active Support that did it, I didn’t want builder anyway.
Posted in Programming, Rails, Ruby, Sinatra | 1 Comment »
May 24th, 2008 cschneid
Instead of writing a pastebin for semantic data like I had planned (still a good idea I’ll get to eventually), I’ve started working on a blog engine initially written by Ryan Tomayko called Wink. If you visit his blog, you can see the only live instance of Wink. He recently open sourced it with a little cajoling from the rest of the guys in #sinatra.
To get a feel for what it can do, check out Ryan’s post “Administrative Debris”. You can get a very good feel for what Wink is all about: simplicity, consistency, and ease.
Currently it’s not quite in a usable state. If you grab the 0.1 tag off of github, it should run for you, maybe with some tweaking or fighting with it. If you want to give it a shot, please do so, and report back on freenode.org either in #sinatra or #wink on how it went.
Beyond that, we’re going to solidify some of the wibbly-wobbly parts, add a few features, and document how to install and deploy.
I see Wink as being the shining example of what a great sinatra application can be, and I’m glad I got in on the ground floor of it’s open source life.
To grab the source code, or just follow development head over to github at Ryan’s Wink repository, or mine.
Posted in Programming, Rails, Sinatra | No Comments »
May 7th, 2008 cschneid
Turns out I was lying in my last post about not wanting to buy a book about rails. I ended up purchasing “Professional Ruby on Rails” from Amazon a few days ago. Boy is one click shopping dangerous.
Twitter is the thing that changed my mind. Several people came out saying that their pre-release versions were good, and so I just went and bought it. Expect a mini-review once I get it read and absorbed.
Posted in Programming, Rails | No Comments »
May 4th, 2008 cschneid
I’ve finally decided to update my knowledge of Rails to the newer Rails 2.0.
All sorts of stuff has changed, and of course my book “Agile Web Development With Rails” isn’t updated yet. Being cheap, I don’t feel like buying another book. Here are the tutorials and blog posts I’ve run across. Many of these are single purpose on something specific, but hopefully this helps you out.
General
- Akita On Rails has a 2 part series going over the new stuff in Rails 2, and how to use it. (part 1), (part 2)
- Railscasts - short, to the point screen casts going over various Rails features. This has been going since Rails 1 days, but starting at episode 80, it’s all about Rails 2.
Specs
- Not easy to read, but RSpec examples for testing Models, Controllers, Views, and Helpers.
Fixtures
- Foxy Fixtures - easily create has_many and belongs_to type relationships with no cross reference work actually in the fixture.
That’s what I’ve found so far, I know there are a bunch more great resources and posts out there to find. I’ll write follow-up articles as I find the juicy tidbits out there.
Posted in Programming, Rails | No Comments »