Rails

AR#find_eachのlimit/offset

ARのfind_each/find_in_batchesはlimit/offsetをオプションで指定できる。 User.find_each(start: 1000, batch_size: 100) do |user| user.touch end batch_sizeは単純にrelationのlimitにわたされるだけ。 startは>=でprimary keyに対してセットされる。 re…

deviseでさくっと認証作る

有名なやつ。 結論、ちょう簡単にできる。 https://github.com/plataformatec/devise ドキュメントが親切。 Install Gemfileに追記。 gem 'devise' bundle install rails g devise:install 初期設定 devise:installしたら設定項目が表示されるので迷うことは…

accepts_nested_attributes_for でupdateされないパターン

ちょっとハマったのでメモ。 class User < ActiveRecord::Base attr_accessible :name, :profile_attributes has_one :profile accepts_nested_attributes_for :profile end class Profile < ActiveRecord::Base attr_accessible :name, :user_id belongs_to…

herokuにrailsアプリをのせる

他のところにもあるので完全にメモレベル。 herokuのアカウントを作る http://api.heroku.com/signup から。 heroku gem をいれる $ gem install heroku heroku用のkeyを作っておく $ heroku keys:add Enter your Heroku credentials. Email: foo@bar.com Pa…

railsをインストールして起動するまで

ruby本体はrvmで最初から管理したほうがよさそう。 bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) source ~/.bash_profile rvm requirements 最新は1.9.3なんだけど1.9.2にしてみた。 rvm install …