Topic: How can I connect to existing database

Hello community,

This is my first post and first time getting into ruby on rails.  I am a novice and ran into rails when experimenting with Spiceworks.  I decided to learn rails since Spiceworks was built off this technology and I wanted to learn more about how Spiceworks runs in the background.  Well things spead up pretty fast on getting features to work since certain things do not run out the box.  I know to do something big you need to start small but I do not have the luxury because of time constrants. I bought a book Agile Web Development with Rails and got to chapter 6 in one day because it has been that addictive. I never liked command line until this language. 

I can pick up the syntax soon enough but I want to at least get one skill down because I will need to demonstrate the advantage of using this technology in my enviroment versus something I already created in .net.

Is there some step by step tutorial to connect to an external database that runs off of SQLite.  Spiceworks runs off SQLite and we have data I want to pull into my site.  If anyone can help I would appreciate it. Remember I am a novice smile

Re: How can I connect to existing database

Rails guides is your friend: http://guides.rubyonrails.org/ as well as Rails API: http://api.rubyonrails.org/.
See also Michael Hartl's tutorial for more details: http://ruby.railstutorial.org/ruby-on-r … orial-book

Last edited by Javix (2012-07-15 15:42:21)

Re: How can I connect to existing database

I think I will need help on this. I cant display data from database.

rails new demo
cd demo
change .yml to path of external SQLite database
rake db:migrate
rails generate model Customer id:integer first_name:string last_name:string
rails generate controller Customer index

I don't know what to do from there in controller to display the info for view.  I have tried examples but I get a get error in browser.

Re: How can I connect to existing database

Post the error you have, it is really difficult to guess the reason.
You can try to play a little bit in the rails console:

#cd to your application folder
rails c
#you'll get a prompt line to enter commands
#displaying all the customers (like select * from customers)
all_customers = Customer.all 
#you will get either a customers array or an empty array if there is no one in the DB.
#hit 'exit' to quit the rails console

If everything is OK, check the routes.rb file for available routes or run in the terminal/console from the application folder:

rake routes

See more details at Rails guides: http://guides.rubyonrails.org/

Last edited by Javix (2012-07-17 03:06:24)