RailsでのServiceの使い方1


Railsのinstall方法はこちらを参照して下さい。
http://qiita.com/joji/items/0dd0e4a113b65b4c9c09

rails new service_test -d mysql
cd service_test
vi Gemfile

Comment in

gem 'therubyracer', platforms: :ruby
bundle install
rake db:create
rails g scaffold BankAccount money:integer
rake db:migrate

Start rails and create data from browser

rails s -b 0.0.0.0

There are 2 data now.
We wanna transfer money and create 2 data using transaction.
So we will create new method and routes

vi config/routes.rb

Add new routes

config/routes.rb
get 'transfer_money' => 'bank_accounts#transfer_money'
vi app/controllers/bank_accounts_controller.rb 

check routes

bank_accounts_controller.rb
def transfer_money
  render text: "hello"
end

Quiz

Please implement logic that We will transfer money and create 2 data using transaction.

current data is 200 and 100.
One should be 0 and the other should be 300.