21 May 2013

The Ruby Reflector

Topic

ActiveModel

  Source Favicon
By Mike Gunderloy of A Fresh Cup 15 days 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
Email

…at the method, you hardly have to concern yourself with the rest of the class: everything just makes sense.

strong_parameters will be standard in Rails 4.0, but they can be used now in Rails 3.* .

Written by Caleb Thompson

P.S. You can include ActiveModel:: ForbiddenAttributesProtection on a model-by-model basis, but given the level of awesomeness provided I wouldn't recommend it.

robots.thoughtbot.com Read
  Source Favicon
On RailsCasts 2 months 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 3 months 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 3 months 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 6 months 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 6 months ago.
Email
  Source Favicon
Email

Add validation support using ActiveModel includes

Display data validation errors in the form

Use ActiveModel naming conventions for generating form endpoints

Routing

Create the routes needed for displaying a web form and posting the data

Restrict resources to the routes you need using only: # config/routes.rb resources :registration, only: [:new, :create]

Controller and Actions

Create a controller with new and create actions.

respond_with will re-render the new action if …

robots.thoughtbot.com Read
  Source Favicon
By Giles Bowkett of Giles Bowkett 8 months 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
  Source Favicon
By José Valim of Plataformatec Blog 9 months ago.
Email

Similar reasoning applies to most of Active Model modules. There is no need to eager load ActiveModel::Validations because if an application is using it, it will load a framework or a model that actually requires it on boot. You will find that this reasoning will probably apply to most modules in your library.

After defining your eager loads, all you need to do is to define a Railtie and include your eager load namespace in it:

module SimpleForm class Railtie < Rails::Railtie config. …

blog.plataformatec.com.br Read