…API with Rails, I was overwhelmed with the abundance of options available to me. From ActiveModel:: Serializers to JBuilder to Rabl to simply calling .as_json , just choosing which library to use for rendering JSON was a task in and of itself.
A couple weeks and a Sinatra app later, our team was on its way to building a solid, extensible, well-tested JSON API with Rails.
Half way through the project, Diana, an iOS developer, remarked to me: "Being able to create an …
…application is returning more than the client needs. To address this, consider using ActiveModel Serializers instead of #as_json .
The delivery of the response has unnecessary dependencies
Let's say yourhas an endpoint the clients uses for reporting analytics events. Your controller might look something like this: class AnalyticsEventsController < ApiController def create job = AnalyticsEventJob.new(params[:analytics_event])
if job.enqueue head 20 …
First of all, I want to apologize to all for the long time it has taken me to push this humble new code.
I started to work on ActiveModel:: Serializers because I'm interested in the Rails API project in general and ActiveModel:: Serializers in particular. Given that ActiveModel:: Serializers has few contributors, I thought it could be a good opportunity to understand the code and help the community around the project.
I began contributing to the project on a trip to San Francisco…
Weeks of April 22 - May 5, 2013
As I expected, Rails 4.0 last week. And so, now the coverage here is of the new master, which is planned to be was released 4.1.
1ec64297 is the actual tag for 4.0 RC1.
eebb9ddf touches a lot of code to convert ActiveModel to 1.9 hash syntax.
Take for instance the to_param and to_partial_path methods from ActiveModel . You can override them in your models to change how your views will interact with them, and that goes in a per model basis, since you usually won't do that for your entire application. Imagine if you need to change a configuration instead overriding a method: You would have to do something weird like this:
# A regular configuration inside an initializer config. action_view . parameterize_method = :slug # But …
Theanswer to such things is ActiveModel , which provides some tools to get you started on building models that aren't based off ::Base . Unfortunately, however, there are a lot of great features, such as validation, that you can't easily get this way.
Enter active_attr , a fantastic gem by , that helps you bootstrap your new non-persisted models and get into the good stuff. Chris's gem provides validation, mass-assignment, and …
It declares a few attributes and some validations. Thanks to ActiveModel you could use anything provided by its validations package in a form object.
By declaring the attributes a form object brings a simple means of implementing mass assignment protection without requiring any sort of sanitization and without poisoning the model with attr_accessible and jumping through hoops in tests to create valid objects to work with.
If an attribute assigned to the form doesn't exist, the assignment …
Aaron 's blog post: Is it Live
Why 4 is a big deal
Ruby on Rails : Strong parameters