避免重复ActiveRecord :: Base.connection_pool.with_connection

时间:2015-12-01 10:43:01

标签: ruby-on-rails ruby

我有一些使用ActiveRecord来保存某些数据的函数。

def create_location(user_location)
  ActiveRecord::Base.connection_pool.with_connection do
    loc = Location.new(user_location.attrs)
    loc.save!
  end
end

如何避免重复代码?

因为现在每个方法我都必须将所有内容都包裹在ActiveRecord::Base.connection_pool.with_connection内。

0 个答案:

没有答案