RailsのMySQLの環境にアクセスできるようにしておく
前回、RailsをMySQLに対応させたが、
「rails new sample_mysql -d mysql」で作ったsample_mysqlに
ブラウザからアクセスできるようにしてなかったので、
ちょっと設定しておく
Apacheの設定を変更し、再起動。
$ sudo vi /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80> ServerName www.yourhost.com # !!! Be sure to point DocumentRoot to 'public'! DocumentRoot /home/dev/sample_mysql/public ←sample_mysqlにアクセスするよう設定 RailsEnv development <Directory /home/dev/sample_mysql/public> ←sample_mysqlにアクセスするよう設定 # This relaxes Apache security settings. AllowOverride all # MultiViews must be turned off. Options -MultiViews </Directory> </VirtualHost>
$ sudo service httpd restart
rails newで作成したsample_mysqlに移動。
$ cd sample_mysql
とりあえずHello, world!を表示するコントローラを作成。
$ vi app/controllers/sample_controller.rb
class SampleController < ApplicationController def index render :text => 'Hello, world!' end end
ルーティングを設定。
$ vi config/routes.rb
root 'sample#index'
これで
http://サーバーのIPアドレス/
にアクセスすると「Hello, world!」が表示される。