rails console
>ActiveRecord::Base.connection.native_database_types

$ rails g

テーマ
$ rails g web_app_theme:theme --app-name="Tiempo" --theme=amro --engine=haml

ページャー
$ rails g kaminari:config
ページャーテーマ
$ rails g kaminari:views github -e haml


認証
$ rails generate devise:install
$ rails g devise User

項目変更
class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable
      t.encryptable
      t.confirmable
      t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
      # t.token_authenticatable


      t.timestamps
    end

    add_index :users, :email,                :unique => true
    # add_index :users, :reset_password_token, :unique => true
    # add_index :users, :confirmation_token,   :unique => true
    # add_index :users, :unlock_token,         :unique => true
    # add_index :users, :authentication_token, :unique => true
  end

  def self.down
    drop_table :users
  end
end

rails g scaffold Post title:string content:text draftable:boolean commentable:boolean posted_at:datetime markdown:text user_ip:string user_agent:string created_at:datetime updated_at:datetime referrer:string users:references

rails g scaffold Gallery name:string comment:string content_type:string user_id:integer created_at:datetime user_ip:string user_agent:string referrer:string updated_at:datetime image:string posts:references

rails g scaffold Exif width:integer height:integer bits:integer comment:string make:string model:string orientation:integer x_resolution:decimal y_resolution:decimal resolution_unit:integer software:string date_time:datetime ycb_cr_positioning:integer exposure_time:decimal f_number:decimal exposure_program:integer iso_speed_ratings:integer date_time_original:datetime date_time_digitized:datetime shutter_speed_value:decimal aperture_value:decimal metering_mode:integer flash:integer focal_length:decimal color_space:integer pixel_x_dimension:integer pixel_y_dimension:integer sensing_method:integer exposure_mode:integer white_balance:integer scene_capture_type:integer sharpness:integer gps_version_id:string gps_latitude_ref:string gps_latitude:datetime gps_longitude_ref:string gps_longitude:datetime gps_altitude_ref:string gps_altitude:datetime gps_time_stamp:string gps_satellites:string gps_status:string gps_measure_mode:string gps_dop:decimal gps_speed_ref:string gps_speed:decimal gps_track_ref:string gps_track:decimal gps_img_direction_ref:string gps_img_direction:decimal gps_map_datum:string gps_dest_latitude_ref:string gps_dest_latitude:decimal gps_dest_longitude_ref:string gps_dest_longitude:decimal gps_dest_bearing_ref:string gps_dest_bearing:decimal gps_dest_distance_ref:string gps_dest_distance:decimal gps_processing_method:string gps_area_information:string gps_date_stamp:string gps_differential:integer created_at:datetime updated_at:datetime galleries:references

#rails g scaffold User email:string encrypted_password:string reset_password_token:string reset_password_sent_at:datetime remember_created_at:datetime sign_in_count:integer current_sign_in_at:datetime last_sign_in_at:datetime current_sign_in_ip:string last_sign_in_ip:string password_salt:string confirmation_token:string confirmed_at:datetime confirmation_sent_at:datetime failed_attempts:integer unlock_token:string locked_at:datetime nickname:string location:string comment:string created_at:datetime updated_at:datetime

rails g scaffold UserIcon content_type:string user_ip:string user_agent:string referrer:string created_at:datetime updated_at:datetime icon:string users:references

rails g scaffold Comment title:string comment:text commentable_id:integer commentable_type:string user_id:integer user_ip:string user_agent:string referrer:string created_at:datetime updated_at:datetime

rails g scaffold UserSetting exifable:boolean commentable:boolean publish:boolean style:integer users:references

Usersに属性追加
$ rails g migration add_nickname_to_users nickname:string
$ rails g migration add_location_to_users location:string
$ rails g migration add_comment_to_users comment:string

$ rails g devise Admin

項目変更
class DeviseCreateAdmins < ActiveRecord::Migration
  def self.up
    create_table(:admins) do |t|
      t.database_authenticatable :null => false
      #t.recoverable
      #t.rememberable
      t.trackable
      t.encryptable
      # t.confirmable
      # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
      # t.token_authenticatable


      t.timestamps
    end

    add_index :admins, :email,                :unique => true
    # add_index :admins, :reset_password_token, :unique => true
    # add_index :admins, :confirmation_token,   :unique => true
    # add_index :admins, :unlock_token,         :unique => true
    # add_index :admins, :authentication_token, :unique => true
  end

  def self.down
    drop_table :admins
  end
end

$ rails g devise:views

コメントオブジェクト作成
$ rails g comment

項目追加
class CreateComments < ActiveRecord::Migration
  def self.up
    create_table :comments do |t|
      t.string :title, :limit => 50, :default => ""
      t.text :comment
      t.references :commentable, :polymorphic => true
      t.references :user
      t.timestamps

      #add by j69
      t.string :user_ip
      t.string :user_agent
      t.string :referrer
  end

    add_index :comments, :commentable_type
    add_index :comments, :commentable_id
    add_index :comments, :user_id
  end

  def self.down
    drop_table :comments
  end
end

ファイルアップローダー
$ rails g uploader image
$ rails g migration add_image_to_galleries image:string
$ rails g uploader icon
$ rails g migration add_image_to_usericons icon:string

==================================
$ rake db:migrate

schema.rbへのDB反映
$ rake db:schema:dump
schema.rbからDBへの反映
$ rake db:schema:load

初期ページ作成
$ rails g controller home index

Tiempo::Application.routes.draw do
  root :to => 'home#index'


認証後でないとアクセスさせたくないコントローラにフィルタ追加
class PostsController < ApplicationController
  before_filter :authenticate_user!


認証エラー用の要素追加
  3. Ensure you have flash messages in app/views/layouts/application.html.erb.
     For example:

       <p class="notice"><%= notice %></p>
       <p class="alert"><%= alert %></p>


タグ
rails g acts_as_taggable_on:migration
rake db:migrate
日付でソートできるよう日付を追加
rails g migration AddCreatedAtToTags created_at:datetime

ASSETSのコンパイル
$ bundle exec rake assets:precompile RAILS_ENV=production

◆delayed_job
$ rails g delayed_job
$ rake db:migrate

開発時のジョブ起動
$ rake jobs:work

バックグランドジョブの起動
$ RAILS_ENV=production script/delayed_job start
バックグランドジョブの終了
$ RAILS_ENV=production script/delayed_job stop

キューの削除
rake jobs:clear

