Slide 1

Slide 1 text

Made In Japan Akira Matsuda

Slide 2

Slide 2 text

rails new % rails new ruby_on_ales % git init, add, commit

Slide 3

Slide 3 text

whoami ★name: Akira Matsuda ★twitter: @a_matsuda ★github: amatsuda

Slide 4

Slide 4 text

I do ★Ruby ★Rails

Slide 5

Slide 5 text

Japan

Slide 6

Slide 6 text

Ruby

Slide 7

Slide 7 text

DEMO

Slide 8

Slide 8 text

before do ★ Gemfile gem 'rspec-rails' gem 'capybara-webkit' ★ % rails g rspec:install

Slide 9

Slide 9 text

begin

Slide 10

Slide 10 text

action_args https://github.com/asakusarb/action_args

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Installation ★ Gemfile gem 'action_args' ★ % bundle

Slide 13

Slide 13 text

generate scaffold % rails g scaffold ale name price:integer % rake db:migrate

Slide 14

Slide 14 text

It works! % rails s

Slide 15

Slide 15 text

It’s green! % rails g rspec:install % rake spec

Slide 16

Slide 16 text

interactive_rspec https://github.com/amatsuda/ interactive_rspec

Slide 17

Slide 17 text

Installation ★ Gemfile gem 'interactive_rspec' ★ % bundle

Slide 18

Slide 18 text

Usage % rails c > irspec > (1+1).should eq(2)

Slide 19

Slide 19 text

spec a = AlesController.new a.index a.instance_variable_get('@ales').should eq(Ale.all)

Slide 20

Slide 20 text

runnig request specs % rake spec:requets

Slide 21

Slide 21 text

a request spec ★ spec/requests/ales_spec.rb feature "Ales" do scenario 'creating an ale' do visit '/ales/new' ll_in 'ale_name', :with => 'ruby' ll_in 'ale_price', :with => '1' click_button 'Create Ale' page.should have_content('ruby') end end

Slide 22

Slide 22 text

hocus_pocus https://github.com/amatsuda/hocus_pocus

Slide 23

Slide 23 text

Installation ★ Gemfile gem 'hocus_pocus' ★ % bundle

Slide 24

Slide 24 text

generating request specs

Slide 25

Slide 25 text

Adding a label image

Slide 26

Slide 26 text

Using good ol’ helpers ★ app/helpers/ales_helper.rb def lagel_image(ale) image_tag("#{ale.name}.png") end ★ app/views/ales/index.html.erb <%= label_image(ale) %>

Slide 27

Slide 27 text

active_decorator https://github.com/amatsuda/ active_decorator

Slide 28

Slide 28 text

Installation ★ Gemfile gem 'active_decorator' ★ % bundle

Slide 29

Slide 29 text

generating a decorator % rails g decorator ale

Slide 30

Slide 30 text

Decorate! ★ app/decorators/ale_decorator.rb def label_image image_tag "#{name}.png" end ★ app/views/ales/index.html.erb <%= ale.label_image %>

Slide 31

Slide 31 text

Validating models ★ app/models/ale.rb validates_presence_of :name

Slide 32

Slide 32 text

HTML5 has client-side validation ★ app/views/ales/_form.html.erb <%= f.text_ eld :name, required: 'required' %>

Slide 33

Slide 33 text

Not DRY ★ app/models/ale.rb validates_presence_of :name ★ app/views/ales/_form.html.erb <%= f.text_ eld :name, required: 'required' %>

Slide 34

Slide 34 text

html5_validators https://github.com/amatsuda/ html5_validators

Slide 35

Slide 35 text

Installation ★ Gemfile gem 'html5_validators' ★ % bundle

Slide 36

Slide 36 text

I18n

Slide 37

Slide 37 text

i18n_generators https://github.com/amatsuda/ i18n_generators

Slide 38

Slide 38 text

Installation ★ Gemfile gem 'i18n_generators' ★ % bundle

Slide 39

Slide 39 text

generate i18n % rails g i18n ja

Slide 40

Slide 40 text

generate i18n (more) % rails g i18n fr % rails g i18n pt-br

Slide 41

Slide 41 text

Pagination

Slide 42

Slide 42 text

Kaminari https://github.com/amatsuda/kaminari http://railscasts.com/episodes/254- pagination-with-kaminari

Slide 43

Slide 43 text

Installation ★ Gemfile gem 'kaminari' ★ % bundle

Slide 44

Slide 44 text

Paginate! ★ app/controllers/ales_controller.rb def index(page) @ales = Ale.page(page) end

Slide 45

Slide 45 text

hocus_pocus (Reprise) https://github.com/amatsuda/hocus_pocus

Slide 46

Slide 46 text

end