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

Rails Bootcamp [Sesión 04, 05]

Rails Bootcamp [Sesión 04, 05]

Transcript

  1. RAILS BOOTCAMP 4 JUNIO 2016

  2. ACTIONVIEW ACTIONCONTROLLER

  3. Datos del Modelo a la Vista: Controladores

  4. app/controller/home_controller.rb class HomeController < ApplicationController def index @nombre = "Felipe"

    @people = Person.all end end
  5. La “pagina web”: Vistas

  6. $ rails generate scaffold Person

  7. /app/views/person

  8. ERB

  9. erb-loud

  10. <%= @person.first.name %>

  11. erb-silent

  12. <% @person.each do |p| %> <% end %> Se utiliza

    en ciclos u otro código que no se expondrá al usuario
  13. Partials

  14. $ touch app/views/layouts/ _navbar.html.erb

  15. <h1> Hola <% if @nombre.nil? %> Mundo <% else %>

    <%= @nombre %> <% end %> </h1> <hr>
  16. <%= render 'layouts/navbar' %>

  17. Asset Pipeline

  18. LINKS <%= link_to 'Nuevo Post', new_post_path, class: ['hola', 'mundo'] %>

    <%= link_to 'Posts', posts_url, id: 'mundo' %> <%= link_to 'Google', 'http://google.com' %> IMAGENES <%= image_tag 'leyton.jpg' %> CSS/JS (SASS/COFFEESCRIPT) <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks- track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  19. Una vista completa

  20. <%= render 'layouts/navbar' %> <ul> <% @people.each do |var|%> <li>

    <%= image_tag 'leyton.jpg' %> <strong><%= var.name %></strong> <p><%= var.email %></p> </li> <% end %> </ul> <% # RELATIVA %> <%= link_to 'Nuevo Post', new_post_path, class: ['hola', 'mundo'] %> <% # URL COMPLETA %> <%= link_to 'Posts', posts_url, id: 'mundo' %> <% # EXTERNA %> <%= link_to 'Google', 'http://google.com' %>