rake db:schema:dump
rake db:reset
でDB復活。データは消えるっぽい。
気が付いたらrake db:migrateが止まるようになってしもうた。
昔あったメソッドを使おうとする、手動で追加したカラムを追加しようとする、などが原因。
変なことせず、Railsさんのやりたい方法でやらせてあげるのが一番だね。
Showing posts with label activerecord. Show all posts
Showing posts with label activerecord. Show all posts
datetime_selectでnilも使いたい。
datetime_selectは、nil値にはデフォルトでなぜか現在時刻が入る。なぜだ!
こうすればnilできた
Nil value on datetime_select?
こうすればnilできた
f.datetime_select :start, :include_blank => true
Nil value on datetime_select?
Labels:
activerecord,
Rails
一度にいろんな条件でFindしたい
パラメータからFindの条件を作る部分をまとめたかった。
普通の条件なら
cond[:パラメータ] = params[:パラメータ]
でぽんぽん追加してあげればいいんだけど、配列でやりたい条件もあった。
そんな時はこれ。
ActiveRecord Query Building with Multiple and Optional Conditions
こんな感じでやりました。案外簡単にできるもんですね。
普通の条件なら
cond[:パラメータ] = params[:パラメータ]
でぽんぽん追加してあげればいいんだけど、配列でやりたい条件もあった。
そんな時はこれ。
ActiveRecord Query Building with Multiple and Optional Conditions
こんな感じでやりました。案外簡単にできるもんですね。
def create_cond_from_params(params)
cond = []
args = {}
#p1は指定したい
if !params[:p1].blank?
cond << "p1 = :p1"
args[:p1] = params[:p1]
end
# p2、あるかな?
if params[:p2]
cond << 'p2 IS NOT NULL'
end
return [] if cond.blank?
[cond.join(" AND "), args]
end
Labels:
activerecord,
Rails
ぽりぽり
Polymorphic Relationships => Rails Wiki
結構簡単にできる。べんり~
でもこういうときはインターフェースが欲しいっす。それっぽいことは出来るんだろうけど。。
追記
できた。Polymorphicにくっつけたクラスのゲッターで、それを拡張してあげればOK。aliasとclass << くっつけたクラス で。
しかし、何かイボーな気配がする。
結構簡単にできる。べんり~
でもこういうときはインターフェースが欲しいっす。それっぽいことは出来るんだろうけど。。
追記
できた。Polymorphicにくっつけたクラスのゲッターで、それを拡張してあげればOK。aliasとclass << くっつけたクラス で。
しかし、何かイボーな気配がする。
Labels:
activerecord,
Rails
Subscribe to:
Posts (Atom)
Author
Archive
Labels
- actionmailer (2)
- ActionView (2)
- activerecord (5)
- Ajax (1)
- apache (2)
- authlogic (2)
- awk (2)
- bash (4)
- block (1)
- cache (1)
- capistrano (1)
- crontab (1)
- Debian (1)
- deployment (1)
- design (2)
- design pattern (1)
- exception_notifier (1)
- factory_girl (2)
- firefox (1)
- flash (1)
- git (2)
- haml (1)
- html (1)
- javascript (5)
- jQuery (3)
- life (2)
- linux (3)
- lisp (2)
- mail (1)
- migration (1)
- mysql (2)
- Passenger (2)
- prototype.js (1)
- Rails (26)
- Rails3 (1)
- rake (1)
- restful_authentication (2)
- Rspec (3)
- ruby (10)
- rubygems (1)
- screen (1)
- script/console (1)
- Security (1)
- shouda (1)
- shoulda (3)
- subversion (2)
- sudo (1)
- tdd (1)
- testing (4)
- thunderbird (1)
- UI (1)
- unix (1)
- vim (3)
- work (1)
- xargs (1)
- xss (1)
- zsh (1)