ruby on rails の変更点   


* rails の install [#i0fe8007]

*** rvm (CentOS5-32bit系) [#s09a3bcc]
 cp /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-bundle.crt.bak
 wget http://curl.haxx.se/ca/cacert.pem -O /etc/pki/tls/certs/ca-bundle.crt  
 \curl -L https://get.rvm.io | bash -s stable --ruby 
 source /usr/local/rvm/scripts/rvm
 yum -y install gcc44 gcc44-c++ python26 sqlite3-devel git
 wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/5/i386/epel-release-5-4.noarch.rpm
 rpm -ivh epel-release-5-4.noarch.rpm
 yum -y install python26 --enablerepo=epel
 yum install git
// yum -y install gcc44 gcc44-c++ python26 sqlite3-devel git
// wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/5/i386/epel-release-5-4.noarch.rpm
// rpm -ivh epel-release-5-4.noarch.rpm
// yum -y install python26 --enablerepo=epel
// rvm use 2.0.0
// rvm use 2.0.0@rails4b1 --create
 gem install rails -v 4.0.0 --no-rdoc --no-ri
// PYTHON=python26 CC=gcc44 CXX=g++44 
 gem install sqlite3 -v '1.3.8'
 cp /usr/bin/python /usr/bin/python.bak
 rm /usr/bin/python
 ln -s /usr/bin/python26 /usr/bin/python
 CC=gcc44 CXX=g++44  gem install libv8 -v '3.16.14.3'
 cp /usr/bin/python.bak /usr/bin/python
 bundle install
// bundle install

*** version 確認 [#a4646681]
 ruby -v
 ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

 gem --version 
 2.0.7

 rails --version
 Rails 4.0.0

*** rails プロジェクトの作成(毎回必要な作業) [#d926192a]
 mkdir /tmp/railstest
 cd /tmp/railstest
 rails new ./

*** default 構築で必要になる gem [#zcf2a851]
 gem install minitest -v '4.7.5'
 gem install json -v '1.8.1'

Gemfile~
gem 'therubyracer', platforms: :ruby をオンに

 bundle install 
 rails server

* postgresql を db に使う場合 [#tb1786b1]
CentOS5-32bit系
 wget http://yum.postgresql.org/9.1/redhat/rhel-5-i386/pgdg-centos91-9.1-4.noarch.rpm
 rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
 yum install postgresql91-server postgresql91-devel
 chkconfig postgresql-9.1 on
 /etc/init.d/postgresql-9.1 initdb
 /etc/init.d/postgresql-9.1 start

CentOS5-64bit系
 wget http://yum.postgresql.org/9.1/redhat/rhel-5-x86_64/pgdg-centos91-9.1-4.noarch.rpm
 rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
 yum install postgresql91-server.x86_64 

CentOS6-64bit系
 wget http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
 rpm -ivh pgdg-centos*.noarch.rpm
 yum -y install postgresql93 postgresql93-server postgresql93-devel
 /etc/init.d/postgresql-93 initdb
 /etc/init.d/postgresql-9.3 initdb
 
///var/lib/pgsql/data/pg_hba.conf~
/var/lib/pgsql/9.3/data/pg_hba.conf

 ident -> trust 

  chkconfig postgresql[-9.3] on
 /etc/init.d/postgresql[-9.3] start 

 psql --username=postgres

 create user railstest;
 create database railstest owner railstest;
 ctrl+d

CentOS5-64bit/32bit
 export PATH=/usr/pgsql-9.1/bin/:$PATH
 gem install pg -v '0.16.0'

CentOS6-64bit
 export PATH=/usr/share/pgsql:$PATH
 gem install pg -v '0.16.0'

*** passenger [#p9ee2afb]
passenger(WebRick を使わない apacheの連携モジュール) の install
 yum -y install curl-devel httpd-devel apr-devel apr-util-devel
 gem install passenger 
 passenger-install-apache2-module

httpd.conf
 LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
 PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.19
 PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby
 ServerTokens ProductOnly
 ServerSignature Off

SELinux 設定
 setenforce 0
 /etc/init.d/httpd restart
 grep httpd /var/log/audit/audit.log | audit2allow -M passenger
 semodule -i passenger.pp
 setenforce 1
 /etc/init.d/httpd restart

*** その他 [#n7964302]
必要であれば[[PostGIS]]のインストール

*** rails プロジェクトの作成(毎回必要な作業) [#x5b87d9b]
 mkdir /tmp/railspg
 cd /tmp/railspg
 rails new ./ -d postgresql

/tmp/railspg/Gemfile~
 gem 'therubyracer', platforms: :ruby をオンに
 gem 'activerecord-postgis-adapter'
 gem 'will_pagenate'
 gem 'ransack'

 bundle install

/tmp/railspg/config/database.yml
 データベース名、ユーザ、パスワードを適切に設定

 rails server

*** rails_admin を入れる [#b2f4e186]
Gemfile
 gem 'devise'
 gem 'rails_admin'

database.yml
 adapter: postgis
 postgis_extension: true

config/environments/development.rb
 config.action_mailer.default_url_options =
    { :host => '192.168.0.100:3000' }

wizard のようなものが開く~
インストールしたいディレクトリと、テーブル名を入れる

 rails g devise:install
 rails g rails_admin:install
 rails server
 rake db:migrate
 rails server

----
memo
*** model の作成 [#h41b7747]
 rails generate model quake

migrate ファイルの編集~
db/migrate/xxxx_create_quakes.rb
 t.column :name     ,:string
 t.column :location ,:geometry ,:srid => 4326
 t.column :magnitude,:float
 t.timestamps

 rake db:migrate

 insert into quakes (location,magnitude) values ('東京',ST_GeomFromText('POINT(ST_GeomFromText('POINT(139.76608399999998 35.681382)',4326),3.0);

*** route の指定 [#j39db784]
config/routes.rb
 get ':controller(/:action(/:id(.:format)))'

*** controller の作成 [#w7571a57]
controllers/hoge_controller.rb
 # coding: utf-8
 
 class HogeController < ApplicationController
   def index
        @quakes = Quake.all
   end
 end

*** view の作成 [#rccabc9a]
views/hoge/index.html.erb
 <table border="1">
        <tr>
            <th> name </th>
            <th> latitude </th>
            <th> longitude </th>
            <th> magnitude </th>
        </tr>
 
 <% @quakes.each do |quake|%>
         <tr style="background-color: <%= cycle('#FFffFF','#C0ffC0') %>" >
                <td></td>
                <td><%= quake.lonlat.y %></td>
                <td><%= quake.lonlat.x %></td>
                <td><%= quake.magnitude %></td>
        </tr>
 <% end %>
 </table>
----
.rb のコメントアウト~
SINGLE LINE
 # puts "hello"

MULTI LINE
 class Hoge 
 =begin
     def test
        puts "hello"
     end
 =end
 end

.erb のコメントアウト~
SINGLE LINE
 <%#= @hogehoge #%>

MULTI LINE
 <%- if false -%>
    <%= @hogehoge %>
 <%- end -%>

----

* deploy [#m1af2764]
プロジェクトのディレクトリごとコピー
 bundle install

psql 
 createuser -U postgres 【project名】 
 createdb -U postgres -O 【project名】 -E UTF-8 -T template_postgis 【project名】

 rake db:migrate

その他、fixture で初期投入すべきデータをいれておく



毎回やる作業
 chown -R apache.apache 【projectdir】
 service httpd restart