I’m learning RoR in Windows 7 with InstantRails.
I got into sqlite3 successfully and created a table named Trades with a handful of columns. I got out of that and into ruby console.
>> class Trade < ActiveRecord::Base; end
=> nil
>> trade = Trade.new
=> #<Trade barterID: nil, title: nil, message: nil, created_at: nil, updated_at: nil>
>> trade.class
=> Trade(Table doesn't exist)
I double-checked that by getting back into sqlite3 and it’s definitely there. I know the table isn’t named “Trade” so I tried re-naming is as Trade, but it gave even more errors. I read that the table name should be in plural format, so I think I have that part right.
Any help on why it says the table doesn’t exist? I’ll give any details I haven’t thought of.
In Rails, you have to do a total abstraction of your DB. Whatever you work with sqlite or mysql the steps are the same (except the first configuraion, but sqlite doesn’t need).
The normal process is the following :
Generate a Model with rails generator
rails generate model Trade
Edit the associated migration file, (something like 2012xxxxxxxx_create_trades.rb in
db/migrate/) and put it the schema of Trade. syntax hereRun
rake db:migratein order to apply the changes to the databaseUse your Model