sudo -s cd /usr/ports/www/rubygem-rails/ make install make clean
gem update rails
プロジェクト(作業用ディレクトリ)の作成
%rails helloworld
ディレクトリ(helloworld)と,ファイル群が作成される
%cd helloworld
script/generate controller helloworld #script/generate: Command not found.が表示される cd app emacs controllers/helloworld_controller.rb
以下,appディレクトリ下で作業。まず,コントローラを作成。
# 編集前のcontrollers/helloworld_controller.rb # しかし、自分のファイルはこのような内容でなく、何も表示されなかった class HelloController < ApplicationController end
# 編集後のcontrollers/helloworld_controller.rb class HelloworldController < ApplicationController def index @message = "hogehoge" end end
HTML表示用viewを作成
emacs views/helloworld/index.rhtml
views/helloworld/index.rhtmlの中身
<HTML> <head> <title>hello world</title> </head> <body> <h1>Hello world (rails) project</h1> <%= @message %> <!-- koko ga Ruby on Rails --> </body> </HTML>
ポート番号を指定して起動。以下の例では6000番ポートを指定
script/server -p 6000
ブラウザでアクセス
http://your.host.name:6000/helloworld/index/