ル微王徴

Rails動作確認

最終更新:

rubyocho

- view
メンバー限定 登録/ログイン

Rails動作確認

テスト・スクリプトの起動

  • ユーザのホーム・ディレクトリから
    rails testapp
    cd testapp
    
  • サービス起動
    $ ruby script/server
    => Booting WEBrick...
    => Rails application started on http://0.0.0.0:3000
    => Ctrl-C to shutdown server; call with --help for options
    [2007-05-06 14:00:12] INFO  WEBrick 1.3.1
    [2007-05-06 14:00:12] INFO  ruby 1.8.5 (2006-08-25) [i386-linux]
    [2007-05-06 14:00:12] INFO  WEBrick::HTTPServer#start: pid=2344 port=3000
    
  • ブラウザから閲覧 http://localhost:3000/
  • サービス停止
    CTL+C
    [2007-05-06 14:14:13] INFO  going to shutdown ...
    [2007-05-06 14:14:13] INFO  WEBrick::HTTPServer#start done.
    

データベース接続 SQLiteの確認

itemモデルを生成

ruby script/generate model item
     exists  app/models/
     exists  test/unit/
     exists  test/fixtures/
     create  app/models/item.rb
     create  test/unit/item_test.rb
     create  test/fixtures/items.yml
     create  db/migrate
     create  db/migrate/001_create_items.rb

vi config/database.yml

development:
  adapter: sqlite3
  database: dev.db

SQLite3のデータベースを作る。テーブルを作る

$ sqlite3 dev.db  
SQLite version 3.3.6
Enter ".help" for instructions
sqlite> CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT);
sqlite> .quit

itemモデル

$ ruby script/generate scaffold item
     exists  app/controllers/
     exists  app/helpers/
     create  app/views/items
     exists  app/views/layouts/
     exists  test/functional/
 dependency  model
     exists    app/models/
     exists    test/unit/
     exists    test/fixtures/
  identical    app/models/item.rb
  identical    test/unit/item_test.rb
  identical    test/fixtures/items.yml
     create  app/views/items/_form.rhtml
     create  app/views/items/list.rhtml
     create  app/views/items/show.rhtml
     create  app/views/items/new.rhtml
     create  app/views/items/edit.rhtml
     create  app/controllers/items_controller.rb
     create  test/functional/items_controller_test.rb
     create  app/helpers/items_helper.rb
     create  app/views/layouts/items.rhtml
     create  public/stylesheets/scaffold.css

サービス起動

$ ruby script/server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2007-05-06 15:15:03] INFO  WEBrick 1.3.1
[2007-05-06 15:15:03] INFO  ruby 1.8.5 (2006-08-25) [i386-linux]
[2007-05-06 15:15:03] INFO  WEBrick::HTTPServer#start: pid=3416 port=3000

ブラウザから閲覧 http://localhost:3000/items/

  • データ一覧から新規作成
  • データ入力
  • 入力ができて、データ一覧

サービス停止

CTL+C
[2007-05-06 14:14:13] INFO  going to shutdown ...
[2007-05-06 14:14:13] INFO  WEBrick::HTTPServer#start done.
目安箱バナー