Create a rails app called Gwitter at any location you want. Change directory to the same rails app and follow the STEPS as below.
[STEP 1] add mysql dependency to Gemfile and then fire bundle install
prayag@prayag:~/workspace_rails/Gwitter$ vi Gemfile
gem 'mysql', '2.8.1'
prayag@prayag:~/workspace_rails/Gwitter$ bundle install
find gem INSTALLATION DIRECTORY
prayag@prayag:~/workspace_rails/Gwitter$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-10-12 patchlevel 286) [i686-linux]
- INSTALLATION DIRECTORY: /home/prayag/.rvm/gems/ruby-1.9.3-p286
- RUBY EXECUTABLE: /home/prayag/.rvm/rubies/ruby-1.9.3-p286/bin/ruby
- EXECUTABLE DIRECTORY: /home/prayag/.rvm/gems/ruby-1.9.3-p286/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/prayag/.rvm/gems/ruby-1.9.3-p286
- /home/prayag/.rvm/gems/ruby-1.9.3-p286@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
gems installed can be checked with following command,
prayag@prayag:~/workspace_rails/Gwitter$ ls -l /home/prayag/.rvm/gems/ruby-1.9.3-p286/gems/
total 156
drwxrwxr-x 3 prayag prayag 4096 Oct 30 12:08 actionmailer-3.2.8
drwxrwxr-x 3 prayag prayag 4096 Oct 30 12:07 actionpack-3.2.8
drwxrwxr-x 3 prayag prayag 4096 Oct 30 12:07 activemodel-3.2.8
drwxrwxr-x 4 prayag prayag 4096 Oct 30 12:08 activerecord-3.2.8
[...]
drwxrwxr-x 7 prayag prayag 4096 Nov 25 16:49 mysql-2.9.0
[...]drwxrwxr-x 2 prayag prayag 4096 Oct 30 12:09 rails-3.2.8
drwxrwxr-x 5 prayag prayag 4096 Oct 30 12:09 railties-3.2.8
[...]
OR simply with,
prayag@prayag:~/workspace_rails/Gwitter$ gem list
*** LOCAL GEMS ***
actionmailer (3.2.8)
actionpack (3.2.8)
activemodel (3.2.8)
activerecord (3.2.8)
activeresource (3.2.8)
activesupport (3.2.8)
arel (3.0.2)
builder (3.0.4)
bundler (1.2.1)
[...]
rails (3.2.8)
railties (3.2.8)
rake (0.9.2.2)
[...]
[STEP 2] configure config/database.yml for mysql
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: mysql
username : eccount
password:eccount
host: 10.13.212.4
database: BadalKarkhana
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
[STEP 3] scaffold(resource) User
Following command will generate CRUD files for a model User,
prayag@prayag:~/workspace_rails/Gwitter$ rails generate scaffold User firstName:string lastName:string active:boolean
[STEP 4] migrate database using rake
prayag@prayag:~/workspace_rails/Gwitter$ bundle exec rake db:migrate
== CreateUsers: migrating ====================================================
-- create_table(:users)
-> 0.1665s
== CreateUsers: migrated (0.1666s) ===========================================
References
[1] 5 Getting Up and Running Quickly with Scaffolding, http://guides.rubyonrails.org/getting_started.html
[2] My five favorite “hidden” features in Rails 3.2, http://blog.plataformatec.com.br/2012/01/my-five-favorite-hidden-features-in-rails-3-2/
[3] Learn Web Development with Rails, http://ruby.railstutorial.org/chapters/a-demo-app#top
No comments:
Post a Comment