By Tumayun.
Rails separate read and write.
- Ruby >= 2.0.0
- Rails >= 4.1.0
Put this line in your Gemfile:
gem 'master_slave'
Then bundle:
% bundle
-
Run command
bundle exec rails g master_slave:config
. -
Modify config/shards.yml.
Class User < ActiveRecord::Base
...
end
ActiveRecord::Base.slave do
User.all
end
ActiveRecord::Base.using(:slave_name) do
User.all
end
Feel free to message me on Github (tumayun) or Gmail ([email protected]).
- Fork, fix, then send me a pull request.