Your are here: Home // Posts Tagged With rails
Rails 3.1 Asset Pipeline
Podcast: Play in new window
| Download
Assets in Rails before version 3.1 were kept in the /public folder. In Rails 3.1 they’ve been moved to /app/assets and function in a slightly different way. Here are some of the highlights:
Javascript assets written in Coffeescript will now be compiled to Javascript.
CSS assets written in SASS or SCSS will now be compiled to CSS
Other templating...
ActiveModel – Making Ruby Classes Behave Like Models
Podcast: Play in new window
| Download
I’ve been working on an ORM for Cassandra. One of the things I’ve been using to build the ORM is ActiveModel. ActiveModel gives you modules you can add to your class that makes it behave like an ActiveRecord Model.
Here are some of the features you can add to your classes with ActiveModel.
Attribute Methods
Callbacks
Dirty Attributes (knowing which attributes...
Tags: ActiveModel, activerecord, attributes, callbacks, dirty, json, naming, observers, rails, ruby on rails, serialization, state machine, translation, validation, xml
Web Forms in Ruby on Rails
Podcast: Play in new window
| Download
Building web forms in Rails was something that confused me when I was new to the framework. This is probably due to the fact that there are some methods that are a lot alike and there are a couple of ways of instantiating a form that do different things.
The first way of building a form that is probably the most common is by using the ‘form_tag’ helper...
Polymorphic Associations
Podcast: Play in new window
| Download
Rails has the concept of Polymorphic associations, which are associations that can be of different data types. For example, let’s say we have a Comment model. A comment in your app can be on a post or a page. Rather than creating a PostComment model and a PageComment model, you can set up your Comment model to have a polymorphic association to a Page or...
Rails Controllers: Before, After, and Around Filters
Podcast: Play in new window
| Download
In your Rails controllers you have filters you can place on incoming requests, outgoing responses, or wrap around your actions.
Before filters are run on requests before the request gets to the controller’s action. It can return a response itself and completely bypass the action.
The most common use of before filters is validating a user’s authentication...
ActiveRecord Callbacks
Podcast: Play in new window
| Download
You can get a full list of the ActiveRecord callbacks here.
Callbacks are a handy way of insuring specific behaviors on your models as well as managing the events that follow the callbacks.
For example, a before_destroy callback can be called to destroy associated objects. (This is best done on the association with :dependent => :destroy, but it makes...
The DRY Principle
Podcast: Play in new window
| Download
According to The Pragmatic Programmer by Andy Hunt and Dave Thomas, “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.”
Last week I talked about extending your Ruby on Rails application. This is because in many cases in order to avoid repeating your logic across multiple classes (models or...
Extending Ruby on Rails
Podcast: Play in new window
| Download
I’m going to be talking about the DRY principle next week. However, before I jump into that, I need to discuss how to extend Ruby on Rails so you know where you can put functionality to keep your application DRY.
There are a couple of standard places people put code that isn’t a Model, View, Controller, or Helper:
The ‘lib’ folder – This is...
Tags: classes, extending, extensions, gems, junk drawer, lib, modules, plugins, rails, ruby, ruby on rails
Ruby on Rails Routing
Podcast: Play in new window
| Download
Ruby on Rails routing can be a little confusing. Here are some of the high points.
The root path is specified by the ‘root’ method. It matches the ‘/’ path and behaves like ‘match’.
The ‘match’ method will match the requested path to the string passed to match and route to the controller and action specified....
Tags: collection, helpers, member, rails, rest, restful resources, routes, routing, ruby, ruby on rails
Rails Engines
Podcast: Play in new window
| Download
Rails Engines are a terrific way of mounting on Ruby on Rails application into another.
A Rails Engine is basically a Rails application with an Engine class installed. The main application—the application your engine is mounted into—uses the generators, rake tasks, and routes from engines automatically. As of Rails 3.1, rake tasks are provided...

