Articles

That nifty question mark

Here’s a pattern you see a lot of in Ruby:

  foo.bar if foo.respond_to?(:bar)

I do this kind of thing frequently, as I’m a big fan of ducktyping over checking an object’s class explicitly. I’m not concerned with the class of an object as long as it does what I’m asking.

Io has a nice and simple way of doing this, built into the language:

Migrate already!

For some reason, people seem to have an issue with migrations … they get them confused with schemas. Allow me to explain.

A lot of people seem to sit on changes they want to make models, collecting changes for “one big migration.” As if it were of utmost important that the migration be complete.

Introducing Badger

Badges are an expected, even necessary hassle for conference organizers; they identify who’s allowed in the door, help people start conversations, and end up as souveniers once the conference is finished. The problem with badges, though, is that they can be a real pain to put together.

Adding Date and Time Formats

This is nothing new, but, having seen enough Rails developers using custom helpers to do the same thing, I thought it might warrant a quick tip.

If you’re entering dates/times in your fixtures, you’re probably familiar with this trick:

  ---
  item1:
    id: 1
    name: foo
    created_at: <%= 3.days.ago.to_s(:db) %>

Memoizing nil and false

Here’s a common technique:

def foo
  @foo ||= compute_foo
end

For those that don’t know, this is an example of memoization; we only computefoo if @foo hasn’t been assigned a value.

RubyGem-based Rails Plugins

One thing about Rails that’s a bit annoying to those of us who have been using Ruby for a long time is the lack of support for RubyGem-based plugins.

You have to take into account the kind of torture conversations like this were, for years upon years, and the kind of psychological damage it did to all of us:

What’s Ruby’s CPAN?

Anything like CPAN for Ruby?

What’s the package/library manager for Ruby?

Ruby sucks! Where’s CPAN?

Superfast Testing How To: In-Memory SQLite3

Audience: This is for both application and plugin developers. Especially plugin developers. Always use SQLite3 in-memory databases as your default for plugin tests which require a database.

ActiveTest: TestHelper Bug Fix

There was an issue with test_helper variables set on Test::Unit::TestCase not being set properly. Values would always be the default because of the way class inherited attributes are passed down the hierarchy. You now need to require the active_test framework and any other plugins you have installed at the end of RAILS_ROOT/test/test_helper.rb.

Rails Views,

I’ve noticed recently, looking through my traffic, that a good number of people still come around looking for my dom_id articles.

I think it’s worth mentioning that you shouldn’t be using my dom_id code anymore- if you’re running a up-to-date version of Rails (maybe only edge?) you’ll want to use the simply_helpful plugin instead; I do.

It wraps the DOM ID related stuff with lots of RESTful goodness, so use it.

TFWY 1.0.0 Released

I’m proud to announce (along with my co-author, Martin Owen) the v1.0.0 release of the Ruby bindings to the TheyWorkForYou API. TheyWorkForYou is a “non-partisan, volunteer-run website which aims to make it easy for people to keep tabs on their elected and unelected representatives in Parliament.”

The Ruby bindings currently support all of the services offered by v1.0.0 of the API, and makes accessing the data very, very easy to do.

ตำรับตำรา (How-Tos) - Translate page to Thai. | Rails Fire

ตำรับตำรา (How-Tos) - Translate page to Thai.

หน้า how-to เป็นการรวมเกร็ดและข้อแนะนำต่างๆ ที่คุณอาจจะใช้ประโยชน์ในการใช้งาน Rails ได้

* การตรวจสอบชื่อผู้ใช้และกำหนดสิทธิ์การใช้ระบบ
* Background Processes และ Cron Jobs
* Starling + Workling
* RabbitMQ + Workling