welcome to
Ruby on Rails
Olar :)
Elaine Naomi Watanabe
Full-stack Developer (Plataformatec)
Mestre em Ciência da Computação (USP)
github.com/elainenaomi
@elaine_nw
Por que Rails?
David Heinemeier Hansson
David Heinemeier Hansson
DHH
Framework extraído de
uma aplicação real
Convenção sobre configuração
DRY (Don't repeat yourself)
Objetivo:
Objetivo:
Simplificar a vida
Por onde começar?
MVC
ViewModel
Controller
apresentação
intermediador
dados +
lógica de negócio
Vamos ver isso no Rails
URL localhost:3000/notes
resposta
esperada
URL localhost:3000/notes
GET /notes
http
get '/notes', to: 'notes#index'
config/routes.rb
GET /notes
controllers/notes_controller.rb
get '/notes', to: 'notes#index'
class NotesController < ApplicationController
def index
@notes = Note.all
end
end
controllers/notes_controller.rb
get '/notes', to: 'notes#index'
class NotesController < ApplicationController
def index
@notes = Note.all
end
end
controllers/notes_controller.rb
get '/notes', to: 'notes#index'
class NotesController < ApplicationController
def index
@notes = Note.all
end
end
class Note < ApplicationRecord
end
models/note.rb
create_table :notes do |t|
t.string :content
t.timestamps
end
banco de dados*
class Note < ApplicationRecord
end
models/note.rb
class NotesController < ApplicationController
def index
@notes = Note.all
end
end
<ul>
<% @notes.each do |note| %>
<li><%= note.content %></li>
<% end %>
</ul>
views/notes/index.html.erb
class NotesController < ApplicationController
def index
@notes = Note.all
end
end
URL localhost:3000
navegador
● Nota 1
● Nota 2
● Nota 3
CRUD on Rails
HTTP methods
GET
READ
POST
CREATE
PUT /PATCH
UPDATE
DELETE
DESTROY
resource: Notes
/notes GET
/notes/1 GET
/notes/new GET
/notes/1/edit GET
POST
PUT/
PATCH
DELETE
#index
#show
#new
#edit
#create
#update #destroy
E na prática,
como é criar uma app?
github.com/elainenaomi/hello-rails
Quer saber mais?
Documentação do Rails
http://guides.rubyonrails.org/
Ruby on Rails: coloque sua aplicação web nos trilhos
Vinícius Baggio Fuentes
Cucumber e RSpec: Construa aplicações Ruby com testes e especificações
Hugo Baraúna
Tutoriais em português do RailsGirls
http://guides.railsgirls.com/guides-ptbr/
Guidelines da Plataformatec
http://guidelines.plataformatec.com.br/

Bootcamp de Rails - CaquiCoders Meetup