Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Development with Cuba - Ruby Fun Day 2014

Web Development with Cuba - Ruby Fun Day 2014

In this workshop you will learn to build web applications with Cuba. The workshop is intended for anyone who wants to learn to create a web application with Cuba and other minimalistic tools from scratch. Experience with other web frameworks is not required. However, it's recommended to have some basic knowledge of the Ruby programming language.

Francesco Rodríguez

October 23, 2014
Tweet

More Decks by Francesco Rodríguez

Other Decks in Programming

Transcript

  1. Qué pasa si … • Ingresas a una ruta diferente

    a “/bienvenido”, 
 por ejemplo: “/talks”.
 • Agrega una condición (`on`) si la ruta “/talks”
 no existe y retorna el siguiente mensaje: 
 “Muy pronto podrás ver las charlas aquí”.
  2. views/layout.mote <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Ruby Fun Day

    2014</title> </head> <body> <header> <h1>Ruby Fun Day 2014</h1> </header> ! <div id="content"> {{ content }} </div> </body> </html>
  3. views/talks.mote <div class="panel"> <h1>New talk</h1> ! <form action="/talks" method="post"> <input

    type="text" name="talk[title]" placeholder="title"> <textarea name="talk[description]" placeholder="description"></textarea> <input type="submit" value="Create talk"> </form> </div>
  4. views/layout.mote ! <body> <header> <h1>Ruby Fun Day 2014</h1> </header> !

    <div id="content"> {{ content }} </div> </body>
  5. app.rb require "cuba" require "mote" require "mote/render" ! Cuba.plugin(Mote::Render) !

    Cuba.use(Rack::Static,
 urls: %w(/js /css /img),
 root: "./public")
  6. Qué pasa si … • Pruebo los métodos: `Talk.create()`, `Talk.[]`,

    
 `Talk.all`, `Talk.update`, etc … en la consola 
 de Ruby.
  7. views/talks.mote <div class="panel"> <h1>New talk</h1> ! <form action="/talks" method="post"> <input

    type="text" name="talk[title]" placeholder="title"> <textarea name="talk[description]" placeholder="description"></textarea> <input type="submit" value="Create talk"> </form> </div>
  8. views/talks.mote <div class="panel"> <h1>New talk</h1> ! <form action="/talks" method="post"> <input

    type="text" name="talk[title]" placeholder="title"> <textarea name="talk[description]" placeholder="description"></textarea> <input type="submit" value="Create talk"> </form> </div>
  9. app.rb Cuba.define do on("talks") do on(get) do render("talks") end !

    on(post, param("talk")) do |params| # ... end end end
  10. app.rb ! Cuba.define do on("talks") do on(get) do render("talks") end

    ! on(post, param("talk")) do |params| talk = Talk.create(params) ! res.redirect("/tasks") end end end
  11. views/talks.mote ! <div class="panel"> <h1>Talks</h1> ! % talks.each do |talk|

    <p> <a href="#">{{ talk.title }}</a> </p> <p> {{ talk.description }} </p> % end </div>
  12. views/talks.mote ! <div class="panel"> <h1>Talks</h1> ! % talks.each do |talk|

    <p> <a href="#">{{ talk.title }}</a> </p> <p> {{ talk.description }} </p> % end </div>
  13. views/talks.mote ! <div class="panel"> <h1>Talks</h1> ! % talks.each do |talk|

    <p> <a href="#">{{ talk.title }}</a> </p> <p> {{ talk.description }} </p> % end </div>