Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def self.find_or_new(params = {}, opts = {})
- opts[:id] ||= params[:id]
- begin
- find(opts[:id])
- rescue ActiveRecord::RecordNotFound
- Address.new(params)
- end
- end
- def self.messy_way(id = nil)
- if id
- begin
- find(id)
- rescue ActiveRecord::RecordNotFound
- Address.new
- end
- else
- Address.new
- end
- end
- def self.messy_way_refactor(id = nil)
- if id
- find_or_rescue(id)
- else
- Address.new
- end
- end
- def find_or_rescue(id)
- begin
- find(id)
- rescue ActiveRecord::RecordNotFound
- Address.new(params)
- end
- end
Add Comment
Please, Sign In to add comment