Tuesday, November 27, 2007

Hiatus

I'd like to say a short sorry for being away for such a long time. We are both on a short hiatus due to an overwhelming work load. Please be patient with us, as things should be up and running again in a few days... I hope...

W

Tuesday, November 6, 2007

Validation Caution

So I was implementing validation rules on a model the other day,
and the model started acting really weird afterward :(

Sometimes it'll save the object, most of the time it wont.
After a few attempts to locate the problem, I noticed
an object can be saved if the boolean attribute
is set to true, but won't save if it's set to false.

turns out this is what's causing all the troubles

validates_presence_of

don't use validate_presence_of to evaluate any boolean or numeric type variables,
because if you a value of 0, it'll be treated as nil

instead, this is what I changed it to

validates_inclusion_of attributes, :in => [true, false]

and life is wonderful once again

J

Monday, November 5, 2007

RESTful Cheatsheet

I found a very handy cheatsheet that I would like to share with you guys. I've found it very helpful through my RESTful endeavors:

http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf

Enjoy!

W

Friday, November 2, 2007

collection_singular_ids

I was taking a look at the has_and_belongs_to_many and has_many relationships.

Going through the documentation, I found the ability to retrieve the ids of each relationship. Sometimes that can be useful. So I decided to give it a try. Here is the documentation:

collection(force_reload = false) - returns an array of all the associated objects. An empty array is returned if none are found.
...
collection_singular_ids - returns an array of the associated objects ids

I was thinking... "Alright, this looks simple enough". Thinking that collection would allow me to write:

user.cars

So, I thought if I wanted to retrieve the ids, I could do this:

user.cars_singular_ids

Boy was I wrong! I got an "undefined method" error... at this moment in time, I'm thinking "HUH?!?! But the documentation says so..."

After looking around for a bit, I found the solution. Apparently, it's all in the lack of punctuation! What the documentation is really saying is that we should specify the singular form of the collection with _id attached, like so:

user.car_ids

This reminds me of a joke I once heard of which explained the importance of punctuation:

A professor wrote "A woman without her man is nothing" on the chalkboard and told his students to punctuate it. All the males in the classroom wrote "A woman, without her man, is nothing." However, all the females in the classroom wrote "A woman: without her, man is nothing!" Clearly, punctuation is important!

Hope you guys don't have to bump your heads against the wall for as long as I did!

W

Vector Graphics

I've always liked the look of vector graphics. I always find the effects produced from these images to be captivating and appealing. Hence, since we're playing around with RoR, I thought it would be neat to generate some vector graphics.

At first, I thought this would be a daunting task for someone who rarely touches any type of art. I was almost scared to open up Photoshop CS2. However, I found a website that was enough to get me going. I had to play around with the functions of CS2 first though to get the hang of things since I'm a total newbie! However, as I became more comfortable with what I was doing, I found that it was pretty simple to create vector graphics.

I'll post up some examples of my work later!

W