[Web]Ruby on Rails | Cocoa練習帳

[Web]Ruby on Rails

以前、『[iOS][Web]iPhoneアプリケーションとサーバ間の通信』の回でRuby on Railsを取り上げたが、今回は、Railsそのものを取り上げる。




以前の回では、~/Doccuments/rails/配下に、workbookというアプリケーション環境を生成したが、今回は、その並びにweblogというアプリケーション環境を生成する。




$ cd ~/Doccuments/rails/
$ rails new weblog
$ cd weblog
$ ls
Gemfile
Gemfile.lock
README.rdoc
Rakefile
$ rake db:create



TOPページを静的コンテンツから、動的なものに変更する。




$ rails generate controller home index
$ vi app/views/home/index.html.erb
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
<h1>Hello, Rails!</h1>  ←追加
$ mv public/index.html public/old.index.html
$ vi config/routes.rb 
Weblog::Application.routes.draw do
  get "home/index"
  root :to => 'home#index'  ←追加
end



サーバ起動。




$ rails server



「http://localhost:3000/」にアクセスすると、「index.html.erb」に追加した文言が表示されているはずだ。




関連情報
Ruby on Rails Guides: Getting Started with Rails

実践 Ruby on Rails Webプログラミング入門?無駄なく迅速な開発環境



【Cocoa練習帳】
http://www.bitz.co.jp/weblog/

http://ameblo.jp/bitz/(ミラー・サイト)