Ye Zheng wrote quite a detailed account (in Chinese) about our first CodeJam in the Beijing office already, so I’ll just be brief. I had a great time pairing with other colleagues that I haven’t worked with before. In hindsight I was quite amazed how much we accomplished and how smooth it went.
I […]
Archive for the 'Ruby' Category
ActiveResource and handling a weird 204 response from a remote rails controller
Published February 9th, 2008 in Ruby and Rails.In the examples given in ActiveResource Rails API, when ActiveResource does a PUT (e.g. update) to a remote RESTful rails controller, the rails controller is supposed to return a HTTP code of 204 (No Content).
But if the remote rails controller actually does that:
head :no_content #204
The Http response that ActiveResource receives is a Net::HTTPNoContent, with no […]
Recently I started using ActiveResource to talk to a RESTful controller (which is also done in Rails 2). It is very nice and simplifies a lot. With Rails 2, out of the box you can create a sample RESTful server and client in 3 minutes:
Server:
>> rails test_server
>> cd test_server
>> script/generate scaffold Account […]
I was searching for simple JSON parsing in Rails and found only the Rails 2.0 way: ActiveSupport::JSON.decode. In old version of Rails (1.2.6) there’s only JSON.encode…
So I googled and found here that you can do YAML::load ‘{”key”:”value”}’
A few things I learned about ActiveRecord after_create (and other callbacks)
Published November 2nd, 2007 in Ruby and Rails.1. after_create does not get inherited
class Animal < ActiveRecord::Base
after_create :feed_on_milk
def feed_on_milk
self.immunity_level += 1
end
end
class Cat < Animal
end
The after_create does not get inherited, and so our poor little cats won’t get milk! To retain the after_create hook, you’ll need to do:
class Cat < Animal
after_create :feed_on_milk
end
2. after_create is an array of symbols
If you call after_create on same […]
TextMate bundle to Run Focused Test on a module
Published October 9th, 2007 in Ruby and textmate. 2 CommentsOn our Ruby on Rails project we use TextMate. Run Focused Test is one of our favourite features. However we have some tests that are modules. e.g. we have
class CatTest < Test::Unit::TestCase
include AnimalTests
… and then some Cat-specific tests
end
class DogTest < Test::Unit::TestCase
include AnimalTests
… and then some Dog-specific tests
end
One annoying thing is that after we […]
I’m a lazy blogger. But one reason to do it more often is to write about what I have learned and therefore reinforce my memory. A few months ago I worked with the wonderful Jake Scruggs and learned about RSpec and mocking out the ‘new’ method of a class. Today at work […]
Suppressing warnings in Ruby (in my case, assert_select)
Published July 11th, 2007 in Ruby and Rails.assert_select outputs warnings to stderr about invalid HTML problems (something like a mismatching closing
), yet the assertion still passes/fails as expected. So, instead of fixing the real problem by digging through our layout and partials rhtmls and find the mismatching
, I just want to suppress the warnings. :)
From http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/210670
def […]
