LoginSignup
1
1

More than 5 years have passed since last update.

RailsでのServiceの使い方1

Last updated at Posted at 2016-08-24

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

スクリーンショット 2016-08-24 23.09.18.png

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

スクリーンショット 2016-08-24 23.19.23.png

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.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1