Monday, July 8, 2013

Implicit Rails features

This post is part of a series of blog posts. So far, there were 2 blog posts, which aim at helping you improve the modularity your Rails applications:

3. Implicit Rails features


The speed with which you start every new Rails application is amazing. 

Within a few days you can have a fully working prototype of almost every application. Obviously, the prototype, by definition, may not be fully ready to production use.

With a really small codebase, the prototype does a lot of things. It's all thanks to many built-in Rails features. 

I call them implicit features. They come almost for free. 

  • CRUD
  • validations
  • maintaining created_at and updated_at
  • displaying errors
  • displaying flash messages
  • redirects between pages
  • pagination
  • uploads
  • sending emails
  • attr_accessible/attr_protected (security)
  • CSRF - security

There's one downside to the implicit features. 

They're rarely documented and covered with tests.


As with every app, there comes a moment, when you need to start providing changes. Sometimes, you may want to rewrite some layers of the application. There's a trend recently that we try to find new ways of working with Rails apps, that is less dependent on ActiveRecord. Some developers rewrite their apps to Sinatra or Padrino. 

It sounds great in theory, but it's harder in practice.

It's good to be aware of such hidden functionalities. At some point, they can become explicit features, with their own tests, so that it's never broken.

If you know more such features, share them in the comments.

No comments: