今時は rvm で管理する.rvm だけインストールしておいて,残りは適当に切替える.
# apt-get install ruby-rvm
インストール可能な ruby パッケージのリストを表示
インストール可能な ruby パッケージリストをアップデートする
アップデートされたパッケージリストを再読み込みする.
バージョン 1.9.2-p290 の ruby をインストールする.
指定バージョンの ruby を利用する.ただし,patch level が変わるだけの時は,upgrade を使う.
1.9.2 (patch level は関係ない) をデフォルトで利用するように設定.
patch level をあげる.
rvm で選択された環境にインストールされた gem の一覧が見られる.
uninstall する.ただし,実際に rm されるわけではないみたい.多分,どっかの meta データで論理的に削除しているだけ.
だぶっているパッケージを最新のみ残して,他のを削除する.
パッケージ名 をアップデートする.
gem install iconv -- --with-opt-dir=/usr/local/
以下古い.rails 2.x 時代の記述
ページの構造解析をするモジュール
ruby の O/R マッパー
% sudo passenger-install-apache2-module
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.5 PassengerRuby /usr/local/bin/ruby18
(2.3 系列)
* rails は rest な設計を目指しているので,設置に関しては virtual host して,対象アプリケーションの URI がホスト名直下になるのがデフォルトになっている気がする.
% cd somewhere % rails hoge && cd hoge % rake db:create % script/generate controller home index (home: コントローラ, index: 最初にアクセスされるべきアクション) % rm public/index.html % vi config/route.rb map.root :controller => "home", :action => "index" % cd /documentroot/xxx/ % ln -s /somewhere/hoge/public hoge % cd elsewhere % vi rails-config.conf RailsBaseURI /anywhere/xxx/hoge/ % vi /usr/local/etc/apache22/httpd.conf Include /elsewhere/rails-config.conf % sudo apache restart
(2009/10/10) 参考サイト:
大体以下のような感じ.
% cd どっか % rails testapp % cd testapp % vi config/route.rb ## 上の記述と同じ % vi config/environment.rb 2 行目辺り: RAILS_ENV = 'development' (開発モード:production => 公開用, development => 開発用)
(ここまで環境設定系)
% vi lib/tasks/db_setup.rake
env = 'development'
database = “bbs_#{env}”
require 'activerecord'
def connect
ActiveRecord::Base.establish_connection(:adapter ⇒ 'sqlite')
end
task :db_setup do
ActiveRecord::Schema.define do
connect
begin
create_database database
rescue
end
end
end
task :db_clean do
ActiveRecord::Schema.define do
connect
end
drop_database database
end
(データベースファイル(hoge.dbとか)を touch するためのプログラム)
% rake db_setup
(上記のやり方は,古いっぽい.)
database.yml が存在する前提で,以下のコマンド.
database.yml は,プロジェクト作成時に以下の内容で作成される.デフォル トデータベースは rails 2.0 以上の場合,sqlite3.
# SQLite version 3.x # gem install sqlite3-ruby (not necessary on OS X Leopard) development: adapter: sqlite3 database: db/development.sqlite3 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
database の名前に,プロジェクトの名前をつけておくと良いかもしれない. このままでも問題なし.
% rake db:create RAILS_ENV=production
% rake db:drop RAILS_ENV=development
(ここまでデータベースそのものの準備)
% script/generate model page % vi db/migrate/2009xxxxx_create_pages.rb class CreatePages < ActiveRecord::Migration def self.up create_table :pages do |t| t.column :title, :string t.column :created_at, :timestamp t.column :name, :string t.column :message, :text t.timestamps end end def self.down drop_table :pages end end % rake db:migrate
(ここまでデータベースの中身の設定)
% script/generate controller home index create (コントローラー名 => home, アクション名 => index, create)
あとは,それぞれ,以下のファイルにプログラム,HTML を書いていく.