Monday, February 21, 2011

decent exposure

I was recently introduced to a nifty little gem called decent_exposure. This allows me to do something like the following in my controller

If this is my user controller, I can replace
  def index
    @users = User.all
  end
with
  expose(:users)

This definitely cleans up the code quite a bit. When things start getting hairy, you can redefine your expose method using a block, like so:
  expose(:users) do
    User.active
  end
This will grab all active users in your database (assuming you have a scope, in your model, that grabs all active users).
The gem does a lot more than I'm gonna cover here, I suggest taking a look at decent_exposure's github page for more info.

No comments:

Post a Comment