Serving Custom JSON From Your Rails API With ActiveModel::Serializers

These days, there are so many different choices when it comes to serving data from an API. You can build it in Node with ExpressJS, in Go with Martini, Clojure with Compojure, and many more. But in many cases, you just want to bring something to market as fast as you can. For those times, I still reach for Ruby on Rails.

With Rails, you can spin up a function API server in a very short period of time. Rails is large. Perhaps you object that there's "too much magic". Have you ever checked out the rails-api gem? It lets you enjoy all the benefits of Rails without including unnecessary view-layer and asset-related code.

Rails-api is maintained by Carlos Antonio Da Silva, Santiago Pastorino, Rails Core team members, and all-around great Rubyist Steve Klabnik. While not busy working on Rails or the Rails API Gem, they found the time to put together the active_model_serializers gem to make it easier to format JSON responses when using Rails as an API server.

ActiveModel::Serializers (AMS) is a powerful alternative to jbuilder, rabl, and other Ruby templating solutions. It's easy to get started with, but when you want to serve data that quite doesn't match up with the way ActiveRecord (AR) structures things, it can be hard to figure out how to get it to do what you want.

In this post, we'll take a look at how to extend AMS to serve up custom data in the context of a Rails-based chat app.

Read More

Writing Custom Plugins for PHP’s MySQLnd

Writing Custom Plugins for PHP’s MySQLnd

Note: This is part five in our Extending MySQL with PHP's MySQLnd Series

While I have previously written custom hooks for specific MySQLnd plugins, like custom routing for mysqlnd_ms, and a custom cache handler for mysqlnd_qc, this time we will be looking at mysqlnd_uh (or user handler) which allows us to write an entire plugin ourselves.

Mysqlnd_uh is the least stable of the mysqlnd plugins, only being available as an alpha. You will most likely need to compile from source.

Read More
Learn about Engine Yard
Try Engine Yard for your Ruby or PHP Apps

The Future of Open Source is in Your Hands

Each year, Black Duck Software and North Bridge Venture Partners host the Future of Open Source survey. Now in its ninth year, the survey is an insightful, occasionally surprising view of the changes in the world of open source technology and community.

Over 1,200 people responded to the survey in 2014.

Some interesting insights:

  • Reducing costs remains the #1 reason people choose open source
  • 80% chose open source for the software quality
  • 72% state that open source software is more secure than proprietary software
  • 50% of enterprises contribute to open source projects (and this is expected to increase)

This is great, but it’s important to our industry that the figures are kept up-to-date That’s why Engine Yard is pleased to be a platinum sponsor of this year’s survey.

So, now it’s time for you to make your voice heard. In 5 minutes or less you can add your voice to the conversation. And trust me on this: enterprises large and small listen to what this survey says.

Take the survey now

When you’re done, pass this on to everyone you know who cares about open source.

Getting Started With Ruby Processing

If you're like me, you love to code because it is a creative process.

In another life, I am a musician. I've always loved music because it represents a synthesis of the concreteness of math and the ambiguity of language. Programming is the same way.

But despite the creative potential of programming, I often find myself spending days working out the kinks of HTTP requests or dealing with SSL certificates. Some part of me yearns for a purely Apollonion environment in which to use code to make something new and unseen.

When I feel a void for purely creative coding, I turn to the Processing language.

Read More

Life Beyond Rails: A Brief Look at Alternate Web Frameworks for Ruby

Before we get started, let’s address the elephant in the room. Rails is great. It really is what you need for large scale production applications most of the time. It has history. And if you got started in Ruby working on the web, chances are Rails is what you are most familiar with. All these things are a fair argument for Rails as the framework of choice for many projects.

The point of this article is not to... derail (sorry, could not resist!) our beloved Rails. The main goal is to shed some light on alternatives that you may or may not have been aware of. Some will focus on small scale projects, others fast prototyping, but all of them will work with Ruby and hopefully you will have fun exploring the frameworks and micro-frameworks that help bring this great language to the web.

Read More

CHECK OUT OUR CURATED COLLECTIONS

Look through our specially curated posts to get focused, in-depth information on a single topic.