about 1 year ago - 4 comments
Recently I switched to Postgres for my Rails database needs. Everything is good, but when running tests I get pages of NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index … spewing into my output. I asked around and got some help from @robtreat2. A quick search lead me to the Postgres docs on…
about 1 year ago - No comments
I remember reading about has_many_polymorphs a couple of years ago, then again last year. Each time around when I wanted some sort of polymorphic has_many :through. Each time I figured, “Eh, it’s just another couple of tables” or “I can just map them in a method in the model, there’s not that much data”. But…
about 1 year ago - No comments
Just wanted to share a quick tip about an error I ran into. When running a Rails migration and changing a column that doesn’t exist, you’ll get an undefined method `type=’ for nil:NilClass error. The cause for me was that I had used change_column on login, which my table didn’t have instead of email, which…
about 2 years ago - No comments
Here’s a little module that will make adding things like Cards.random(4) a breeze! # This module takes care of adding a random scope to records module RandomScope def self.included(model) model.class_eval do if connection.adapter_name == "MySQL" named_scope :random, lambda { |amount| if(amount) {:order => "RAND()", :limit => amount} else {:order => "RAND()"} end } else…
about 2 years ago - 1 comment
You know those adjectives that come after nouns? Well, sometimes you may want to pluralize them correctly in your Rails App. I might have been able to get by with “work_in_processes”, but “bill_of_materialsses” just wasn’t going to cut it. Here’s the technique I used: # Add new inflection rules using the following format: ActiveSupport::Inflector.inflections do…
about 3 years ago - 38 comments
If you’re using a model or controller from an engine in Rails 2.3.2 you may encounter some crazy errors from time to time. Errors like: A copy of ApplicationController has been removed from the module tree but is still active! Or sometimes the even weirder one: can’t dup NilClass In one situation where you get…
about 3 years ago - No comments
This is something that I’ve often needed to do: add a new column to the DB that has a non-null constraint, but also doesn’t have a default value. There are a some options: Forget the DB constraint and use `validates_presence_of` in the model Add a default value for the new column with non-null and then…
about 3 years ago - No comments
about 3 years ago - No comments
As this project has progressed we’ve began using haml and sass to mark up our pages. When I first heard and read about these gems they had me concerned that it was an unnecessary change to the relatively simple languages of html and css. “Why the hell would I want to use percent signs instead…
about 3 years ago - 4 comments
This weekend we rolled the innagural deploy of our top secret new rails app to production. We are currently using Rails 2.1, SQLite and nginx proxying to Mongrel. Why bother with Apache (ever) and MySQL before you have to? Additionally we’re on a 256MB slice from Slicehost which is already serving an FB app, so…
about 2 years ago
Have you used vetal_versions?
http://github.com/laserlemon/vestal_versions
Much cleaner than aav
about 2 years ago
I’ll be sure to check it out the next time I need versioning, thanks!