Marcelo Alves
user

Marcelo Alves

Notes and musings from a web developer in Central California


Featured

notes ruby

JSON.parse with object_class

Posted on .

You can pass an object_class to JSON.parse which will use that class to create an object. Can pass OpenStruct to create a simple object or something like an ActiveRecord class.

json_data = '{"id": 1,"name": "A green door","price": 12.50,"tags": ["home", "green"]}'

parsed_json = JSON.parse(json_data, object_class: OpenStruct)

p parsed_json.name
# "A green door"
Featured

tutorials lambda

Create Images from PDF's Using Lambda

Posted on .

Easily create thumbnails from uploaded PDF’s

Featured

notes ruby

find_by vs find_by!

Posted on .

.find_by will return a nil when record isn’t found. .find_by! will return ActiveRecord::RecordNotFound.