Run query on IRB

Hi All
I never worked with RUBY my fisrt time.

I'd like to run this query by IRB and see how many line it will show
me :

select codigo, nome from teste

My database is postgre 8.4

Look what i did to do it:

irb(main):006:0> Post.find_by_sql “SELECT codigo, tirulo from teste”
NameError: uninitialized constant Post
from (irb):6
irb(main):007:0>

What is going on there?

Thanks

Grato

Have you created a rails application ?

What in your opinion is Post? Ruby expects to find a constant by that name. class names in Ruby are constants. constant is any word that starts with a capital letter.

If say you’ve written a class Post, then you must have done so in a file. You need to require that file when inside irb to load that class.

Yes and it created tha database.yml

development:
adapter: postgresql
encoding: unicode
database: postgres_development
pool: 5
username: postgres
password: 031969

test:
adapter: postgresql
encoding: unicode
database: rubyPostgre_test
pool: 5
username: rubyPostgre
password:

production:
adapter: postgresql
encoding: unicode
database: rubyPostgre_production
pool: 5
username: rubyPostgre
password:

And my query it to be runing on development enviroment.

Can u help me run my query?

Thanks

Hi, if it’s rails.

You should go to your applications root & type ‘ruby script/console’ , if your on a mac you could just type ‘script/console’.

When the console starts, you will be able to do what you were trying to do in your IRB.