Feeds:
Posts
Comments

Archive for November, 2007

RSpec and Attachment_Fu

I’m barely even a beginner at using RSpec, but one of the first tests I needed to do involved Attachment_Fu.
Here’s what I did to get my model to pass validation:
require File.dirname(__FILE__) + ‘/../spec_helper’

describe Image do # # I created the spec/images directory and placed this # test image prior to running [...]

Read Full Post »

nearest power of 2

This is one of the reasons I’m a fan of Ruby:
class << Math def log2(n) log(n) / log(2) end end

class Integer def nearest_power_of_2 2**(Math.log2(self).floor) end end
47.nearest_power_of_2 => [...]

Read Full Post »

initializers

Rails 2.o has a new organizational concept with the addition of the config/initializers directory. By default you will have the inflections.rb and mime_types.rb initializers.
I have used a few different approaches to organizing application constants. However, no approach felt right. I didn’t like ‘polluting’ the environment.rb with them because I never thought that [...]

Read Full Post »

find_or_initialize/create_by_<field>

A new ‘discovery’ today. I love finding the occasional meta programming derived method that isn’t explicitly listed with the other methods on the rails api site.
find_or_initialize_by_<field>find_or_create_by_<field>
They do what you think. For example if I did:
user = User.find_or_initialize_by_login(“stonean”)
If the record exists, all is good. If not, well then you can either get an [...]

Read Full Post »

Komodo Edit – Indenting

To indent a bunch of lines at once just highlight them and hit the Tab key (Shift-Tab to undo indention).

Read Full Post »

Starting lighttpd

I didn’t want lighttpd starting on boot so I removed it:sudo launchctl unload -w /Library/LaunchDaemons/org.macports.lighttpd.plistBut then I couldn’t figure out how to start it. Bummer. Then I finally found:/opt/local/etc/LaunchDaemons/org.macports.lighttpd/lighttpd.wrapper start

Read Full Post »

gem server

In the category of why I haven’t I used this yet (duh!):
run: gem_serverto run as daemon: gem_server –daemon
then access: localhost:8808
Documentation for your installed gems. Nice.
If you don’t have any documentation, run: gem rdoc –all
This will generate the docs for all the gems installed on your system.
Note: gem_server has been deprecated in favor of [...]

Read Full Post »

RubyOnRails Interview Questions – 201

These questions are intended to query for intermediate level knowledge of the Rails framework.
Q) I have two tables, users and addresses. The users table has a foreign key column to the addresses table called address_id. This is a one user to a one address setup. How do I represent that relationship in the User ActiveRecord [...]

Read Full Post »

Interview questions/answers for an entry level Ruby developer.(Use these questions in conjunction with the 101 level Rails questions)
Q) How do you comment out a block of code?
A) Use =begin and =end.
=begin def my_commented_out_method end =end
You could use successive # signs, but that’s just tedious:## def my commented_out_method# end#
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Q) How do [...]

Read Full Post »

RubyOnRails Interview Questions – 101

Interview questions/answers for an entry level RubyOnRails developer:
Q) What site contains the Rails framework documentation?
A) api.rubyonrails.com
Note: When I was starting to learn Rails, there was always a tab open for this site. This is a guess that other developers learning Rails would be utilizing this page as well.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Q) What does RAILS_ROOT represent?
A) The base directory [...]

Read Full Post »