Created
February 23, 2009 23:30
-
-
Save crafterm/69262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# demo of adding a CSV description to any arbitrary object using the 'comma' gem | |
# | |
# http://github.com/crafterm/comma for more info | |
class Book < ActiveRecord::Base | |
# ================ | |
# = Associations = | |
# ================ | |
has_many :pages | |
has_one :isbn | |
belongs_to :publisher | |
# =============== | |
# = CSV support = | |
# =============== | |
comma do | |
name | |
description | |
pages :size => 'Pages' | |
publisher :name | |
isbn :number_10 => 'ISBN-10', :number_13 => 'ISBN-13' | |
url 'Website' | |
end | |
end | |
# ... and if you're using Rails, render supports a :csv modifier | |
class BooksController < ApplicationController | |
def index | |
render :csv => Book.limited(50) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment