25 April 2014

The Ruby Reflector

Topic

ActiveModel

  Source Favicon
By Jessie Young of Giant Robots Smashing Into Other Giant Robots 29 days ago.
Email

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 …

robots.thoughtbot.com Read
  Source Favicon
Email

…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 your API has 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 …

robots.thoughtbot.com Read
  Source Favicon
By santiago.pastorino of WyeWorks Blog - The Team's Voice 6 months ago.
Email

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

blog.wyeworks.com Read
  Source Favicon
By Mike Gunderloy of A Fresh Cup 12 months ago.
Email

Weeks of April 22 - May 5, 2013

As I expected, Rails 4.0 RC1 was released last week. And so, now the coverage here is of the new master, which is planned to be Rails 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.

afreshcup.com Read
  Source Favicon
On RailsCasts 1 year ago.
Email

The ActiveModel:: Serializers gem can help you build JSON APIs through serializer objects. This provides a dedicated place to fully customize the JSON output.

railscasts.com Read
  Source Favicon
By Lucas Mazza of Plataformatec Blog 1 year ago.
Email

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 …

blog.plataformatec.com.br Read
  Source Favicon
By thomasfedb of Transcending Frontiers 1 year ago.
Email

The Rails answer to such things is ActiveModel , which provides some tools to get you started on building models that aren't based off ActiveRecord::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 Chris Griego, that helps you bootstrap your new non-persisted models and get into the good stuff. Chris's gem provides validation, mass-assignment, and …

thefrontiergroup.com.au Read
  Source Favicon
On paperplanes over 1 year ago.
Email

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 …

paperplanes.de Read
  Source Favicon
By santiago.pastorino of WyeWorks Blog - The Team's Voice over 1 year ago.
Email
  Source Favicon
By Giles Bowkett of Giles Bowkett over 1 year ago.
Email

…of the business domain with a Ruby model in a Sinatra app, an ActiveModel in a Rails app, and a Backbone model in JavaScript or CoffeeScript (or both), all at the same time. You might also choose to represent this element of your business domain simultaneously as a succinct atom in a Redis queue, multiple rows in Postgres, and an entire tree in Mongo. Synchronizing these databases, and synching the corresponding code in version control, has countless associated challenges.

gilesbowkett.blogspot.com Read