08 May 2005

Ruby on Rails. What?

Rails should support postgresql-7.4. But what the hell is this error?
No such file to load -- postgres

Ok, this is time for googling. Here is one of the solution. Interface to postgresql is
not included in standard rails distribution (I know, interface to mysql is in included).
Then, another error message appear:
ERROR C42P01 Mrelation "personals" does not exist Fnamespace.c L193 RRangeVarGetRelid: SELECT COUNT(*) FROM personals

Before this I had generate model and controller for table personal. This article has nice intro
to activerecord database tables and columns rules (heading: What's in a Table Name?). Also, refer to
this. i.e. the error is because, Rails guess table for model 'Personal' as 'personals' (smart..).
Then, if model 'Mouse', Rails will guess the table name is 'mouses'. What? My English language
teacher teach me that plural for mouse is mice. So,
class Mouse < ActiveRecord::Base
set_table_name "mice"

To have CRUD in Rails for model 'Personal', I only add one line in the controller, e.g:
class PersonalController < ApplicationController
scaffold :personal

Post a Comment