11 Sep '13, 8am

first_or_initializeにブロック渡せる!ひゃっほい!

first_or_initialize (attributes = nil, options = {}, &block) public Like first_or_create but calls new instead of create . Expects arguments in the same format as Base.new. Show source # File activerecord/lib/active_record/relation.rb, line 131 def first_or_initialize ( attributes = nil , options = {}, & block ) first || new ( attributes , options , & block ) end

Full article: http://apidock.com/rails/ActiveRecord/Relation/first_or_i...

Tweets