DataMapper No Memory Error - Sinatra - mysql

Any ideas as to where I am going wrong here?
Error:
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:291:in `next!': failed to allocate memory (NoMemoryError)
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:291:in `select_fields'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:39:in `select'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:33:in `select'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/adapters/dm-mysql-adapter.rb:99:in `show_variable'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/adapters/dm-mysql-adapter.rb:89:in `character_set'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/adapters/dm-mysql-adapter.rb:54:in `create_table_statement'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/adapters/dm-do-adapter.rb:94:in `create_model_storage'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/adapters/dm-do-adapter.rb:93:in `create_model_storage'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/adapters/dm-do-adapter.rb:57:in `upgrade_model_storage'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/auto_migration.rb:71:in `upgrade_model_storage'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/auto_migration.rb:143:in `auto_upgrade!'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/auto_migration.rb:45:in `send'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/auto_migration.rb:45:in `repository_execute'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-core-1.1.0/lib/dm-core/support/descendant_set.rb:66:in `each'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-core-1.1.0/lib/dm-core/support/subject_set.rb:212:in `each'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-core-1.1.0/lib/dm-core/support/ordered_set.rb:321:in `each'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-core-1.1.0/lib/dm-core/support/ordered_set.rb:321:in `each'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-core-1.1.0/lib/dm-core/support/subject_set.rb:212:in `each'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-core-1.1.0/lib/dm-core/support/descendant_set.rb:65:in `each'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/auto_migration.rb:44:in `repository_execute'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/dm-migrations-1.1.0/lib/dm-migrations/auto_migration.rb:27:in `auto_upgrade!'
from list.rb:51
Code:
require 'rubygems'
require 'sinatra'
require 'omniauth/oauth'
require 'rest-graph'
require 'hashie/hash'
require 'dm-core'
require 'dm-serializer/to_json'
require 'dm-migrations'
require 'dm-timestamps'
require 'dm-validations'
require 'dm-mysql-adapter'
enable :sessions
APP_ID = "XXXXX"
APP_SECRET = "XXXX"
SQLCONN = "mysql://XXXXXXX"
DataMapper.setup(:default, SQLCONN)
class Person
include DataMapper::Resource
property :id, Serial
property :FBid, String
property :visits, Integer
property :first_visit, DateTime
property :recent_visit, DateTime
property :token, String
has n, :links
end
class Link
include DataMapper::Resource
property :id, Serial
property :created, DateTime
property :deactivated, DateTime
property :active, Boolean
belongs_to :person
def self.currentLinks
all(:active == true)
end
end
DataMapper.auto_upgrade!

all(:active == true)
try...
all(:active => true)

Related

"uninitialized constant" error during migration

I'm a newbie in Ruby on Rails and I want to generate a mysql database using migrations.
I tried this command
ruby bin/rake db:drop db:create db:migrate --trace
but I always get this error:
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
uninitialized constant CreateOrganisation::Referential
C:/Sites/blog/db/migrate/20120823053740_create_organisation.rb:13:in `up'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:598:in `exec_migration'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/benchmark.rb:281:in `measure'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:578:in `block in migrate'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with
_connection'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:577:in `migrate'
C:in `migrate'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:991:in `block in execute_migration_in_transacti
on'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:1039:in `ddl_transaction'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:990:in `execute_migration_in_transaction'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:952:in `block in migrate'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in `migrate'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:807:in `up'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:785:in `migrate'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (req
uired)>'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
bin/rake:4:in `<main>'
Tasks: TOP => db:migrate
I tried the commands:
rake db:rollback
rake db:reset
rake db:schema:dump
rake db:schema:load
but in vain.
The file that causes the error (I guess) is:
class CreateOrganisation < ActiveRecord::Migration
def up
create_table :organisations do |t|
t.string :name
t.timestamps
end
change_table :referentials do |n|
n.belongs_to :organisation
end
change_table :users do |u|
u.belongs_to :organisation
end
Referential.reset_column_information
User.reset_column_information
organisation = Organisation.find_or_create_by_name!("Chouette")
Referential.update_all :organisation_id => organisation.id
User.update_all :organisation_id => organisation.id
end
def down
drop_table :organisations
end
end
I tried putting def change..end instead of def up..end/def down..end but I still get the same error
I can't see what I'm missing here.
You're trying to change the table referential and it doesn't exist:
change_table :referentials do |n|
n.belongs_to :organisation
end
The error refers to an uninitialized constant ":referentials", which refers to that particular table.
Consider using a generator to create your migrations until you understand how they work; you can always tweak the generated migrations or write your own from scratch later.
Example
rails generate migration CreateFoo name:string amount:integer owner:string:index
And that will create
class CreateFoo < ActiveRecord::Migration
def change
create_table :foos do |t|
t.string :name
t.integer :amount
t.string :owner
end
add_index :foos, :owner
end
end
Reference
I suggest you read the Rails Migration Guide, which should help you understand how to use migrations.

ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`

I am trying to implement a "comment" feature as part of my assignment for an project I am building.
Earlier in the course we created a comment table and had the Faker gem generate fake comments.
My instructions are as follows:
Comments must be associated with users, so add a user_id foreign key to the comments table. Remember to add an index to it too;
Update the User model so you can call user.comments, and the Comment model so you can call comment.user;
Modify the seeds.rb file to create valid comments when you run db:reset;
Initially I tried to run my rails generate commands but kept running into this error:
▶ rake db:migrate
== 20150508143445 CreateComments: migrating ===================================
-- create_table(:comments)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "comments" already exists: CREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "description" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /Users/jon/code/bloccit/db/migrate/20150508143445_create_comments.rb:3:in `change'
-e:1:in `<main>'
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "comments" already exists: CREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "description" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
/Users/jon/code/bloccit/db/migrate/20150508143445_create_comments.rb:3:in `change'
-e:1:in `<main>'
SQLite3::SQLException: table "comments" already exists
/Users/jon/code/bloccit/db/migrate/20150508143445_create_comments.rb:3:in `change'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
So I discovered that I needed to delete the old table from the start of the course. I did this in the console.
ActiveRecord::Base.connection.execute("drop table comments")
It seemed to work. I was then able to run these in terminal.
▶ rake db:migrate
== 20150508143445 CreateComments: migrating ===================================
-- create_table(:comments)
-> 0.0015s
== 20150508143445 CreateComments: migrated (0.0016s) ==========================
== 20150508152354 DropComments: migrating =====================================
== 20150508152354 DropComments: migrated (0.0000s) ============================
▶ rails g migration AddCommentToUsers commed_id:integer:index
invoke active_record
create db/migrate/20150508155200_add_comment_to_users.rb
▶ rake db:migrate
== 20150508155200 AddCommentToUsers: migrating ================================
-- add_column(:users, :commed_id, :integer)
-> 0.0010s
-- add_index(:users, :commed_id)
-> 0.0012s
== 20150508155200 AddCommentToUsers: migrated (0.0023s) =======================
models/comment.rb
class Comment < ActiveRecord::Base
belongs_to :user
end
models/user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
has_many :posts
has_many :comments
# CarrierWave method for attribute functionality
mount_uploader :avatar, AvatarUploader
# These methods check the role of a user in the database
def admin?
role == 'admin'
end
def moderator?
role == 'moderator'
end
end
migrations/create_comments.rb
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.text :description
t.timestamps null: false
end
end
end
migrations/add_comment_to_users.rb
class AddCommentToUsers < ActiveRecord::Migration
def change
add_column :users, :commed_id, :integer
add_index :users, :commed_id
end
end
In my seeds.rb I have changed
# Create Comments
50.times do
Comment.create!(
# user: users.sample, # we have not yet associated Users with Comments
post: posts.sample,
description: Faker::Lorem.paragraph
)
end
to
# Create Comments
50.times do
Comment.create!(
user: users.sample,
description: Faker::Lorem.paragraph
)
end
Now when I run rake db:reset I get this error.
▶ rake db:reset
-- create_table("advertisements", {:force=>:cascade})
-> 0.0047s
-- create_table("answers", {:force=>:cascade})
-> 0.0010s
-- add_index("answers", ["question_id"], {:name=>"index_answers_on_question_id"})
-> 0.0014s
-- create_table("comments", {:force=>:cascade})
-> 0.0010s
-- create_table("posts", {:force=>:cascade})
-> 0.0010s
-- add_index("posts", ["topic_id"], {:name=>"index_posts_on_topic_id"})
-> 0.0010s
-- add_index("posts", ["user_id"], {:name=>"index_posts_on_user_id"})
-> 0.0014s
-- create_table("questions", {:force=>:cascade})
-> 0.0010s
-- create_table("summaries", {:force=>:cascade})
-> 0.0010s
-- add_index("summaries", ["post_id"], {:name=>"index_summaries_on_post_id"})
-> 0.0010s
-- create_table("topics", {:force=>:cascade})
-> 0.0036s
-- create_table("users", {:force=>:cascade})
-> 0.0015s
-- add_index("users", ["commed_id"], {:name=>"index_users_on_commed_id"})
-> 0.0009s
-- add_index("users", ["comment_id"], {:name=>"index_users_on_comment_id"})
-> 0.0012s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})
-> 0.0015s
-- add_index("users", ["reset_password_token"], {:name=>"index_users_on_reset_password_token", :unique=>true})
-> 0.0017s
-- initialize_schema_migrations_table()
-> 0.0034s
rake aborted!
ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`
/Users/jon/code/Bloccit/db/seeds.rb:45:in `block in <top (required)>'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `times'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `<top (required)>'
-e:1:in `<main>'
Tasks: TOP => db:setup => db:seed
(See full trace by running task with --trace)
Here is the full stack trace:
ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute.rb:138:in `with_value_from_database'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_set.rb:39:in `write_from_user'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods/write.rb:74:in `write_attribute_with_type_cast'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods/write.rb:56:in `write_attribute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods/dirty.rb:96:in `write_attribute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods.rb:373:in `[]='
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/belongs_to_association.rb:83:in `replace_keys'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/belongs_to_association.rb:14:in `replace'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/singular_association.rb:17:in `writer'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/builder/association.rb:123:in `user='
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:54:in `public_send'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:35:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/core.rb:559:in `init_attributes'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/core.rb:281:in `initialize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/inheritance.rb:61:in `new'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/inheritance.rb:61:in `new'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/persistence.rb:50:in `create!'
/Users/jon/code/Bloccit/db/seeds.rb:45:in `block in <top (required)>'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `times'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `<top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:547:in `load_seed'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:139:in `block (2 levels) in <top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/jon/code/Bloccit/bin/rake:8:in `<top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
-e:1:in `<main>'
Tasks: TOP => db:setup => db:seed
I am stumped here. I thought by deleting the old table and running the new generate commands + migrating everything would be in order. Apparently this is not the case.
What am I doing wrong here?
edited to include line 45 of my seeds.rb
Comment.create!(
You have the wrong migration - instead of adding a user_id to comments you add users.commed.
Oops. It can happen to the best of us.
So first let's create a migration to clean up this mistake:
class RemoveCommedFromUsers < ActiveRecord::Migration
def change
remove_column :users, :commed # will also remove the index
end
end
Of course if the App has not been deployed you could just delete the offending migration and run rake db:reset
So lets create the correct migration
rails g migration AddUserToComments user:belongs_to
Which generates the following migration:
class AddUserToComments < ActiveRecord::Migration
def change
add_reference :comments, :user, index: true
end
end
add_reference creates a index and a foreign key in one sweep.

one to many relationship ruby on rails

So I made changes to my changes to subject.rb file here
class CreateSubjects < ActiveRecord::Migration
def up
create_table :subjects do |t|
t.string "name"
t.integer "position"
t.boolean "visible", :default =>false
t.timestamps
end
end
def down
drop_table :subjects
end
end
and then I went ahead and defined page.rb file in
class Page < ActiveRecord::Base
belongs_to :subject
end
Then I got to the terminal
Muhammeds-MacBook-Pro:simple_cms muhammedz786$ rails c
Loading development environment (Rails 4.0.2)
irb(main):001:0> subject = Subject.find(1)
Subject Load (0.3ms) SELECT subjects.* FROM subjects WHERE subjects.id = 1 LIMIT 1
=> #
Then I tried to call the subject.page method and I got the follwoing mistake! What does this mean?
irb(main):002:0> subject.page
**Mysql2::Error: Table 'simple_cms_development.pages' doesn't exist: SHOW FULL FIELDS FROM `pages`**
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'simple_cms_development.pages' doesn't exist: SHOW FULL FIELDS FROM `pages`
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `query'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `block in execute'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `execute'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/mysql2_adapter.rb:222:in `execute'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:301:in `execute_and_free'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:462:in `columns'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:118:in `block in prepare_default_proc'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:67:in `yield'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:67:in `columns_hash'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/association_scope.rb:25:in `column_for'
... 3 levels...
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/association_scope.rb:44:in `each_with_index'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/association_scope.rb:44:in `add_constraints'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/association_scope.rb:19:in `scope'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/association.rb:103:in `association_scope'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/association.rb:87:in `scope'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/singular_association.rb:42:in `find_target'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/association.rb:147:in `load_target'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/association.rb:54:in `reload'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/singular_association.rb:9:in `reader'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/associations/builder/association.rb:70:in `page'
from (irb):2
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
Make sure that your Pages model has a subject_id in the migration, and then make sure to run rake db:migrate

Alias attriibute for column names in Rails

So, I have a db which was setup for an old php app and I cannot touch the way the DB is done.
However, I have some column name in the db that are using some restricted words in Ruby like "class"
So to make it work, I used alias_attribute.
But it's not working. Here is the code:
class Contractor < ActiveRecord::Base
set_table_name "contractors"
alias_attribute :class_type, :class
attr_accessible :about, :alias, :business_entity, :business_logo, :business_name, :city, :class, :county, :created, :email, :founded, :metroarea, :nid, :phone, :state, :status, :street_address, :uid, :zipcode
end
here are the errors:
1.9.3-p125 :001 > Contractor.last
SyntaxError: /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:345: syntax error, unexpected ')', expecting '='
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:343:in `module_eval'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:343:in `define_optimized_call'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:227:in `block in alias_attribute'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:224:in `each'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:224:in `alias_attribute'
from /Users/snoopy/Projects/buildzoom/ruby/service_request/app/models/contractor.rb:3:in `<class:Contractor>'
from /Users/snoopy/Projects/buildzoom/ruby/service_request/app/models/contractor.rb:1:in `<top (required)>'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:469:in `load'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:469:in `block in load_file'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:468:in `load_file'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:353:in `require_or_load'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:502:in `load_missing_constant'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `each'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `const_missing'
from (irb):1
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/snoopy/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
and
1.9.3-p125 :003 > Contractor.where(:zipcode => "94111")
Contractor Load (648.6ms) SELECT `contractors`.* FROM `contractors` WHERE `contractors`.`zipcode` = '94111'
(Object doesn't support #inspect)
=>
The last one only appear when I remove the alias_attribute otherwise it's the same error as first one
I think your problem is the alias name you gave ":class"
class is one of the ActiveRecord methods
you can see it by running this command
Contractor.first.methods
defining this alias simply "override" it in some way and interrupt to rails operation
So, there is the gem safe_attributes who is doing the work.
It's working perfectly so far.

activerecord 3.2.2 association issues with multiple connections

can somebody point out some problems that might occur when im having association problem like this?
my classes are:
class BaseDB < ActiveRecord::Base
self.abstract_class = true
def self.load_configs
self.configurations = YAML::load(load_file)
end
def self.load_file
File.open(file_path)
end
def self.file_path
File.join(File.expand_path('../../../',__FILE__),"config/database.yml")
end
end
class User < BaseDB
has_many :things
end
class Thing < BaseDB
belongs_to :user
end
when I try to run in the console
>BaseDB.load_configs
=> {"my_connection"=>{"database"=>"db2", "adapter"=>"mysql2", "password"=>secret, "host"=>"localhost", "user"=>"root"}, "my_other_connection_test"=>{"database"=>"db1", "adapter"=>"mysql2", "password"=>secret, "host"=>"localhost", "user"=>"root"}}
> BaseDB.establish_connection :my_connection
=> #<ActiveRecord::ConnectionAdapters::ConnectionPool:0x7f69c7a38b98 #mon_entering_queue=[], #automatic_reconnect=true, #mon_count=0, #queue=#<MonitorMixin::ConditionVariable:0x7f69c7a38a58 #waiters=[], #monitor=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x7f69c7a38b98 ...>>, #connections=[], #mon_owner=nil, #reserved_connections={}, #spec=#<ActiveRecord::Base::ConnectionSpecification:0x7f69c7a49718 #adapter_method="mysql2_connection", #config={:password=>"####", :adapter=>"mysql2", :user=>"root", :host=>"localhost", :database=>"db2"}>, #timeout=5, #size=5, #mon_waiting_queue=[]>
> user = User.first
=> #<User id: 8325205, firstname: "goryo", middlename: nil, creeated_at: "2012-03-20 18:02:58", updated_at: "2012-03-20 18:02:58">
> user.things
then i get these errors:
ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/alias_tracker.rb:75:in `connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/alias_tracker.rb:54:in `initial_count_for'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/alias_tracker.rb:12:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/alias_tracker.rb:29:in `call'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/alias_tracker.rb:29:in `default'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/alias_tracker.rb:29:in `[]'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/alias_tracker.rb:29:in `aliased_name_for'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/alias_tracker.rb:17:in `aliased_table_for'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/join_helper.rb:15:in `construct_tables'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/join_helper.rb:14:in `each'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/join_helper.rb:14:in `construct_tables'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/association_scope.rb:37:in `add_constraints'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/association_scope.rb:31:in `scope'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/association.rb:98:in `association_scope'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/association.rb:87:in `scoped'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/collection_association.rb:380:in `find_target'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/collection_association.rb:333:in `load_target'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/collection_proxy.rb:44:in `__send__'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.2/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
from /usr/lib/ruby/1.8/irb.rb:310:in `output_value'
from /usr/lib/ruby/1.8/irb.rb:159:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /usr/lib/ruby/1.8/irb.rb:155:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:154:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:71:in `start'
from /usr/lib/ruby/1.8/irb.rb:70:in `catch'
from /usr/lib/ruby/1.8/irb.rb:70:in `start'
ohh all I needed was to establish ActiveRecord::Base connection as an initial inorder to connect to other tables, it works!
ActiveRecord::Base.establish_connection :my_connection
since my basedb is an abstract class, when you establish a connection ActiveRecord::Base w/c is the superclass doesnt have a connection yet you can check it out
>BaseDB.load_configs
>BaseDB.establish_connection :my_connection
try to query
>User.all
>BaseDB.connected?
=>returns true
>ActiveRecord::Base.connected?
=>nil
for more info about the implementation you can check this out http://api.rubyonrails.org/classes/ActiveRecord/Base.html