How to connect to a remote database through a rails application.

Hello guys,
                 I am trying to figure out how can I connect to a
remote database and retrieve information through a rails application.
I did something like this but didnt work.
I am running rails application on sqlite3 database in my local machine
and I am trying to connect to a remote database which is a postgresql
one.
I put this code in my application controller-----

def myprojects
    ActiveRecord::Base.establish_connection(
           :adapter => "postgresql",
           :database => "database name",
           :host => "192.168.10.21",
           :port => "5432",
           :username => "username",
           :password => "password"
         )

  end
people controller code-----

before_filter :myprojects
@items = Item.find(:all)

view code.......
<% @items.each do |item| %>
  <li><%= item.id %></li>
  <% end %>

But this code doesnt work and it gives me error.

Can any one help?

Why put code overwritting AR::B in your controller?
I would create a model representing the external data and use the
method establish_connection :foo. Where foo is defined in your
database.yml file.

do you mean something like this......
model---
establish_connection :foo

database.yml----
foo:
     adapter: postgresql
     database: "database name"
     host: "host name"
     port: "post number"
     username: "username"
     password: "password"

I tried this way but i am getting an error something like this......

Connection refused - connect(2)

Hello Ir, please provide chaqnges in .yml file...for Mysql...'
I have cretaed MySql datbase and now i want to connect my MySql DB on
rails...

when you are trying to create a app just add these line -d mysql you will get the yml according to mysql and change the username and password according to your mysql password.

when you are trying to create a app just add these line -d mysql you will
get the yml according to mysql and change the username and password
according to your mysql password.

If you have already created the app and want to change it to mysql
then create a new app as Keerhi has suggested
rails new test_app -d mysql
then you can look at database.yml and see what is required.

Colin

when you are trying to create a app just add these line -d mysql you will
get the yml according to mysql and change the username and password
according to your mysql password.

If you have already created the app and want to change it to mysql
then create a new app as Keerhi has suggested
rails new test_app -d mysql
then you can look at database.yml and see what is required.

Colin

Also look at the Gemfile in the new app to see the gem changes required.

Walter

keerthi priya wrote in post #1075820:

when you are trying to create a app just add these line -d mysql you
will
get the yml according to mysql and change the username and password
according to your mysql password.

Thanks ...changing user n apssword is not issue...but it indirectly
creating databse as appname_database...and it causing error..please
provide Solution..
Thanks for your help...

I think you need to try to explain the problem again, it is not clear
what your issue is. It might help if you post the full error message
you are getting. Also post database.yml.

Colin