Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Default Sort Order For Rails models

// provide a default sort order in case an order by clause isn't defined in the find clause
// Place this code somewhere in your model's class file.

        def self.find(*args)
          order_arg = args.collect do |arg|
            if arg.kind_of? Hash 
              if arg.keys[0] == :order
                arg
              end
            end
          end

          if order_arg.compact.empty?
            args << {:order=>"place order by clause here e.g. 'name asc'"}
          end
          
          super
        end

use rake migrations to create schema in production database

// use your migrations to recreate the tables in the testing or production databases

rake migrate RAILS_ENV=production

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS