Rails application with sqlite database

-----> Install the sqlite-ruby gem to work with sqlite database

C:\>gem install sqlite-ruby
Successfully installed sqlite-ruby-2.2.3-x86-mswin32
1 gem installed
Installing ri documentation for sqlite-ruby-2.2.3-x86-mswin32...
Installing RDoc documentation for sqlite-ruby-2.2.3-x86-mswin32...

-----> Download the sqlite3.dll from the following website

http://www.sqlite.org/download.html and drop it in the following folder C:\WINDOWS\system32

-----> Create a rails application as follwoing. It creates a rails directory structure with sqlite as default database and version 2.1.0


F:\ror>rails _2.1.0_ sqlite-test
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create config/initializers
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create script/process
create test/fixtures
create test/functional
create test/integration
create test/unit
create vendor
create vendor/plugins
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create Rakefile
create README
create app/controllers/application.rb
create app/helpers/application_helper.rb
create test/test_helper.rb
create config/database.yml
create config/routes.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/new_rails_defaults.rb
create config/boot.rb
create config/environment.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/about
create script/console
create script/dbconsole
create script/destroy
create script/generate
create script/performance/benchmarker
create script/performance/profiler
create script/performance/request
create script/process/reaper
create script/process/spawner
create script/process/inspector
create script/runner
create script/server
create script/plugin
create public/dispatch.rb
create public/dispatch.cgi
create public/dispatch.fcgi
create public/404.html
create public/422.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/robots.txt
create public/images/rails.png
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create public/javascripts/controls.js
create public/javascripts/application.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log


-----> Navigate to the application folder

F:\ror>cd sqlite-test

F:\ror\sqlite-test>


-----> Generate scaffold

F:\ror\sqlite-test>ruby script/generate scaffold User name:string age:integer
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/users
exists app/views/layouts/
exists test/functional/
exists test/unit/
exists public/stylesheets/
create app/views/users/index.html.erb
create app/views/users/show.html.erb
create app/views/users/new.html.erb
create app/views/users/edit.html.erb
create app/views/layouts/users.html.erb
create public/stylesheets/scaffold.css
create app/controllers/users_controller.rb
create test/functional/users_controller_test.rb
create app/helpers/users_helper.rb
route map.resources :users
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/user.rb
create test/unit/user_test.rb
create test/fixtures/users.yml
create db/migrate
create db/migrate/20080120161843_create_users.rb

------> Change the database configuration file as follows.



-----> Migrate the database

F:\ror\sqlite-test>rake db:migrate
(in F:/ror/sqlite-test)
== 20080120161843 CreateUsers: migrating ======================================
-- create_table(:users)
-> 0.0780s
== 20080120161843 CreateUsers: migrated (0.0780s) ======================================

-----> Run the server

F:\ror\sqlite-test>ruby script/server
=> Booting WEBrick...
=> Rails 2.1.0 application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2008-01-20 22:07:04] INFO WEBrick 1.3.1
[2008-01-20 22:07:04] INFO ruby 1.8.6 (2007-09-24) [i386-mswin32]
[2008-01-20 22:07:04] INFO WEBrick::HTTPServer#start: pid=2804 port=3000


-----> start the browser at http://localhost:3000/users to operate the CRUD operations

-----> To view the database data you may add the mozilla addon SQLite Manager from the following path.

https://addons.mozilla.org/en-US/firefox/addon/5817


After adding this addon to the firefox we need to restart the firefox.

-----> To view the data go to the Tools --> SQLite Manager in the firefox browser. after clicking on the Sqlite Manager in the tools menu, go to Database --> Connect Database from the file dialog open the sqlite file in the application folder.

No comments: