Railsメモ

忘れた頃にみる用。3.2.3。

プロジェクト

  
$ rails new hoge -d mysql  

コントローラー

  
$ rails g controller hoge  

モデル

  
$ rails g model hoge field:type [...]  

型一覧
integerdecimalfloat
stringtextbinary
datedatetimetimestamp
timeboolean


カラム名の変更

  
$ rails g migration rename_aaa_to_bbb  
      invoke  active_record  
      create    db/migrate/20120922045512_rename_aaa_to_bbb.rb  

  
# vi db/migrate/20120922045512_rename_aaa_to_bbb.rb  
class RenameAaaToBbb < ActiveRecord::Migration  
  def up  
    rename_column :table, :aaa, :bbb # 追記  
  end  
end  

データベース更新

  
$ rake db:migrate  

rails runner

バッチ処理するとき便利なやつ。

  
$ rails r script/hoge.rb  

config/routes.rb にルート定義。
config/database.yml にデータベース定義。
Gemfile にgem定義。
script/ の下にバッチ処理おく。
public/index.html いらない。

`autodetect': Could not find a JavaScript runtime

Gemfileに以下を追加。

  
gem 'execjs'  
gem 'therubyracer'  

なんか設定が反映されない

unicornも再起動。