かぴぶろぐ

またかぴったかと思った・・・(´A`;)

Ruby on Rails インストールメモ

カテゴリ[ Ruby on Rails ]
rubyのインストール
ruby-1.8.6.tar.gzを取ってくる。
./configure --prefix=/opt/ruby1.8
make
make install
gemのインストール
ruby setup.rb
/opt/ruby1.8.6/bin/gem install rails
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rake-0.8.1
Successfully installed activesupport-2.0.2
Successfully installed activerecord-2.0.2
.......
....(続く)
デプロイ
rails rails_app -d mysql
rake db:create
mongrelサーバをインストール
gem install mongrel
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed gem_plugin-0.2.3
Successfully installed daemons-1.0.9
....(続く)
mobgrelサーバの起動
[root@centos rails_app]# mongrel_rails start
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready.  TERM => stop.  USR2 => restart.  INT => stop (no restart).
** Rails signals registered.  HUP => reload (without restart).  It might not work well.
** Mongrel 1.1.3 available at 0.0.0.0:3000
** Use CTRL-C to stop.
controllerの生成
script/generate controller hello
scaffoldの実行
script/generate scaffold  book title:string price:intger
      exists  app/models/
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/books
      exists  app/views/layouts/
      exists  test/functional/
      exists  test/unit/
      create  app/views/books/index.html.erb
      create  app/views/books/show.html.erb
      create  app/views/books/new.html.erb
      create  app/views/books/edit.html.erb
      create  app/views/layouts/books.html.erb
      create  public/stylesheets/scaffold.css
  dependency  model
      exists    app/models/
      exists    test/unit/
      exists    test/fixtures/
      create    app/models/book.rb
      create    test/unit/book_test.rb
      create    test/fixtures/books.yml
      create    db/migrate
      create    db/migrate/001_create_books.rb
      create  app/controllers/books_controller.rb
      create  test/functional/books_controller_test.rb
      create  app/helpers/books_helper.rb
       route  map.resources :books
DBを作成
rake db:migrate
(in /var/www/rails_app)
== 1 CreateBooks: migrating ===================================================
-- create_table(:books)
   -> 0.1500s
== 1 CreateBooks: migrated (0.1504s) ==========================================
DBの状態を戻したい場合
DBを戻す(VERSION=0でdrop)
rake db:migrate VERSION=0
DBの内容を更新したい場合
script/generate migration [名前]でバージョンファイルを作成
script/generate migration add_column ←実行したい内容にそった名前にするのが良い。
db/migrateに002_add_column.rbのようなファイルが出来る。
間違えた場合や、バージョンファイル作って要らなくなった場合はdestroy
script/destroy migration add_column
DB更新
rake db:migrate
tableを追加
普通に実行
# script/generate model user
script/generateのオプションについて
  • scaffold ・・・ 全部いり(MVC全)
  • model ・・・ model db test (modelに関するところ)
  • migration ・・・ (DB設定だけ)
再度scaffoldを実行(新しいtable等追加時)
普通に実行
script/destroy scaffold source2 filename:string  content:string
rails対話モード
# script/console
routesの確認
rake routesで見れる。
# rake routes
(in /var/www/rails/code_viewer)
                roles GET    /roles                           {:controller=>"roles", :action=>"index"}
      formatted_roles GET    /roles.:format                   {:controller=>"roles", :action=>"index"}
                      POST   /roles                           {:controller=>"roles", :action=>"create"}
                      POST   /roles.:format                   {:controller=>"roles", :action=>"create"}
             new_role GET    /roles/new                       {:controller=>"roles", :action=>"new"}
   formatted_new_role GET    /roles/new.:format               {:controller=>"roles", :action=>"new"}
            edit_role GET    /roles/:id/edit                  {:controller=>"roles", :action=>"edit"}
  formatted_edit_role GET    /roles/:id/edit.:format          {:controller=>"roles", :action=>"edit"}
                 role GET    /roles/:id                       {:controller=>"roles", :action=>"show"}
       formatted_role GET    /roles/:id.:format               {:controller=>"roles", :action=>"show"}
...(続く)
参考URL

http://kapi.jp/kapi_blog/118

2008年02月15日

関連カテゴリ Ruby on Rails

この記事のコメント

この記事にコメントする