Slide 1

Slide 1 text

Ruby on the web Ruby: from 0 to 100 in 14400 seconds (2) ruby@uniovi: Introducing the Ruby programming language School of Computer Sciences University of Oviedo March 2015

Slide 2

Slide 2 text

Git

Slide 3

Slide 3 text

git clone REPO_URL # make changes… git status git commit -am “Commit message” git push

Slide 4

Slide 4 text

cd /vagrant/projects/jukebox-sinatra git pull #updates repo state git checkout workshop #switches branch Let’s type!

Slide 5

Slide 5 text

git config --global user.email "[email protected]" git config --global user.name "user random"

Slide 6

Slide 6 text

TIP: Use it in your thesis always ;) https://education.github.com

Slide 7

Slide 7 text

Tests

Slide 8

Slide 8 text

“Code without tests is bad code. ” - Michael C. Feathers Working Effectively with Legacy Code

Slide 9

Slide 9 text

Unit Tests Integration Tests Acceptance Tests Smoke / Mutation / Stress TDD / BDD

Slide 10

Slide 10 text

TIP: Use it in your thesis always ;) http://betterspecs.org/

Slide 11

Slide 11 text

Web Dev

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Blocks

Slide 16

Slide 16 text

some_method do |param| param * 2 end

Slide 17

Slide 17 text

Sinatra

Slide 18

Slide 18 text

Time to code! Exercise #0 Hello, world! @ Sinatra https://trello.com/b/ziGtcloe/day-2-user-stories

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

ERB

Slide 21

Slide 21 text

    <% @artists.each do |artist| %>
  • <%= artist.name %>
  • <% end %>

Slide 22

Slide 22 text

html = “
    ” @artists.each do |artist| html << “
  • ” html << artist.name html << “
  • ” end html << “

Slide 23

Slide 23 text

get “/” do erb :”home/show” end

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Persistence

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

class Artist include Mongoid::Document field :name, :type => String embeds_many :songs end

Slide 30

Slide 30 text

> a = Artist.create(:name => “Billy Strayhorn”) #=> #

Slide 31

Slide 31 text

> Artist.where(:name => “Duke Ellington”).first #=> #

Slide 32

Slide 32 text

post “/artist” do artist = Artist.create(params) redirect “/artists” end

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Heroku

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

$ heroku login $ heroku create $ bin/set_mongolab_in_heroku $ git push heroku workshop:master $ heroku logs -t

Slide 37

Slide 37 text

& Rails?

Slide 38

Slide 38 text

To learn more...

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

https://github.com/ruby-uniovi

Slide 41

Slide 41 text

Happy hacking! :-) Tw: @pablorc @varezhh @dg_suarez @dcarral