Ruby on Rails

Ruby on Rails をDebian GNU/Linux上で使う。

参考

Ruby Gems

Railsを簡単にインストールするためGemsをいれる。

まず、以下のパッケージをインストール

apt-get install libzlib-ruby
apt-get install libyaml-ruby
apt-get install rdoc
apt-get install libopenssl-ruby
apt-get install libdrb-ruby
apt-get install liberb-ruby

から、RubyGemsをダウンロード。

# tar xvfz rubygems-**.tgz
# cd rubygems-**
# ruby ./setup.rb

Railsのインストール

# gem install rails

RDBMSのインストール(MySQL)

# apt-get install mysql-server mysql-client mysql-common

テスト

るびまの記事(上記参考リンク参照)に従いテストをする。

/usr/lib/ruby/gems/1.8/gems/activerecord-**/test のall.shを以下のように 書き換える

# diff all.sh.org all.sh
8c8
< ruby -I $1 -e 'Dir.foreach(".") { |file| require file if file =~ /_test.rb$/ }'
---
> ruby -rubygems -I $1 -e 'Dir.foreach(".") { |file| require file if file =~ /_test.rb$/ }'

次にall.shに実行権限を付加。されに、上記ディレクトリの./connections/native_mysql/connections.rbの中身の設定を適宜直す(ユーザ名とパスワード)

その上でテスト開始

# ./all.sh "connections/native_mysql"
Using native MySQL
Loaded suite -e
Started
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 34.225194 seconds.

524 tests, 1689 assertions, 0 failures, 0 errors

エラーコメント

MissingSourceFile in <controller not set>#<action not set>

 MissingSourceFile in <controller not set>#<action not set>

no such file to load -- /config/routes.rb

  • 環境: GNU/Linux Debian Sarge上で発生
  • 原因: 現在位置(ディレクトリ)の把握が失敗している
  • 解決法:以下のコマンドでserverを動かせるディレクトリで、以下のコマンドを打つ。

    (appやscript、configがあるディレクトリ)

    # ruby script/server
    

ActionView::ActionViewError in *****#*****

 ActionView::ActionViewError in Bookmarks#new

Showing /bookmarks/new.rhtml where line #4 raised:

No rhtml, rxml, or delegate template found for bookmarks/_form

Extracted source (around line #4):

1: <h1>New bookmark</h1>
2: 
3: <%= start_form_tag :action => 'create' %>
4:   <%= render_partial 'form' %>
5:   <%= submit_tag "Create" %>
6: <%= end_form_tag %>
7: 

  • 環境: GNU/Linux Debian Sarge上で発生
  • 原因: Railsのバージョンによる記法の違い
  • 解決法:Googleのキャッシュ参照 -> Railsを最新(0.13.1)にしたところ発生せず