It’s Bliss: behind the iconic Windows XP photo

Although it will forever be associated with Windows XP, Bliss was actually the by-product of a love story. It was a regular Friday afternoon in 1996 when photographer Charles O’Rear took the drive through California’s wine country to see his then-girlfriend Daphne.

Chuck, as he introduces himself in conversation, has since married Daphne. Bliss, meanwhile, has gone on to become one of the world’s most iconic photographs, chosen as the default wallpaper of Microsoft’s operating system.

It’s Bliss: behind the iconic Windows XP photo

Although it will forever be associated with Windows XP, Bliss was actually the by-product of a love story. It was a regular Friday afternoon in 1996 when photographer Charles O’Rear took the drive through California’s wine country to see his then-girlfriend Daphne.

Chuck, as he introduces himself in conversation, has since married Daphne. Bliss, meanwhile, has gone on to become one of the world’s most iconic photographs, chosen as the default wallpaper of Microsoft’s operating system.

Source: m.cnet.com.au

Ruby / Rails: Include associations when printing an object to JSON

For the longest time I was trying to figure out how to include associated models when you print out an object to json:

Ruby Code:
@dog = Dog.first
format.json { render json: @dog }

Output:
{
name: ‘Fido’,
breed: ‘Chow’
}

The Dog class has_many :tricks and I want the output to include them. I was hitting the head over myself on trying to figure that out: do I make a method for the Dog class, or do I copy everything to a hash and include the tricks… all ideas I knew in my guts to be the wrong way to do it.

One of the tricky things about being a programmer is trying to figure out the name of the problem itself so you can ask other developers (or google it or ask on stackoverflow). And I was hitting my head on that one as well.

Finally, I managed with “ruby include model associations when printing to JSON” and found this answer: http://stackoverflow.com/questions/2567642/how-to-convert-records-including-include-associations-to-json

So easy! Here’s the solution:

Ruby code:
@dog = Dog.first
format.json { render json: @dog.to_json{ include: :tricks} }

Output:
{
name: ‘Fido’,
breed: ‘Chow’,
tricks: [
{
name: ‘Play dead’,
treats: 10
}
]
}

Sorry for the lack of formatting for the JSON, but hopefully you get the gist. The solution was the .to_json function and the :include parameter.

Edit:

One more thing, you can include sub levels of associations as well:

format.json { render json: @campaign.to_json( include: { venues: { include: :city } } ) }

Shout out to this answer on stackoverflow: http://stackoverflow.com/a/4443360/183880

Previous pageNext page
Back to top