Rails Leer Notas Capítulo 7

2023-01-21   EN  

Catalog Display

Crear el controlador de una tienda, que contiene una acción de índice:
rails generate controller Store index

in principal, debe haber 3 entrada
Afirmar_select ‘H3’, ‘Programación Ruby 1.9’ #H3 debería ser el título del libro.
Afirmar_select ‘.price’, / \ $ h Inscripciones, \ d, \ case
fin

fin

‘Selector CSS, #Select ID, Seleccione Clase
Afirmar_select ‘#main. Entrada’,
Rails.application.routes.draw do
  get 'store/index'

  resources :products
  root to: 'store#index', as: 'store'
end

y luego elimine el público/index.html (si es así).
Defina un archivo variable miembro en el archivo app/controlador/store_controller.rb:

class StoreController < ApplicationController
  def index
    @products = Product.order(:title)
  end
end

@products Obtenga todo el producto de acuerdo con las letras.

editar aplicación/vistas/store/index.html.erb:
< % si aviso %> 
 <p id = "aviso"> < %= aviso %> </p> 
 < % End %> 

 <h1> Tu catálogo pragmático </h1> 

 < % @Products.each do | producto | %> #use la variable miembro de los productos definida en store_controller 
   <div class = "Entrada"> 
     < %= Image_tag (producto.image_url) %> #generate img etiqueta 
     <h3> < %= Product.tital %> </h3> 
     <p> < %= Sanitize (Product.Descript) %> </p> #Turn La descripción en el formulario HTML, que puede tener vulnerabilidades de seguridad. 
     <div class = "Price_line"> 
       <span class = "precio"> < %= number_to_currency (producto.price) %> </span> #formular el precio de salida 
     </div> 
   </div> 
 < % End %>

La siguiente aplicación editar/assets/stylesheets/store.css.scss, agregar formato:

.store {
  h1 {
    margin: 0;
    padding-bottom: 0.5em;
    font:  150% sans-serif;
    color: #226;
    border-bottom: 3px dotted #77d;
  }

  /* An entry in the store catalog */
  .entry {
    overflow: auto;
    margin-top: 1em;
    border-bottom: 1px dotted #77d;
    min-height: 100px;

    img {
      width: 80px;
      margin-right: 5px;
      margin-bottom: 5px;
      position: absolute;
    }

    h3 {
      font-size: 120%;
      font-family: sans-serif;
      margin-left: 100px;
      margin-top: 0;
      margin-bottom: 2px;
      color: #227;
    }

    p, div.price_line {
      margin-left: 100px;
      margin-top: 0.5em; 
      margin-bottom: 0.8em; 
    }

    .price {
      color: #44a;
      font-weight: bold;
      margin-right: 3em;
    }
  }
}

A continuación modificamos el diseño de toda la aplicación y agregamos banner.

Modifique el archivo APP/Views/Lights/Application.html.erb:
<!DOCTYPE html>
<html>
<head>
  <title>MyApp</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body class="<%= controller.controller_name %>">
  <div id="banner">
    <%= image_tag("logo.png") %>
    <%= @page_title || "Pragmatic Bookshelf" %> 
  </div>
  <div id="columns">
    <div id="side">
      <ul>
        <li><a href="http://www....">Home</a></li>
        <li><a href="http://www..../faq">Questions</a></li>
        <li><a href="http://www..../news">News</a></li>
        <li><a href="http://www..../contact">Contact</a></li>
      </ul>
    </div>
    <div id="main">
      <%= yield %>
    </div>
  </div>
</body>
</html>

y luego defina el formato CSS correspondiente para cambiar el nombre de archivo App/Assets/Stylesheets/Application.css al archivo App/Assets/Stylesheets/Application.csss:

#banner {
  background: #9c9;
  padding: 10px;
  border-bottom: 2px solid;
  font: small-caps 40px/40px "Times New Roman", serif;
  color: #282;
  text-align: center;

  img {
    float: left;
  }
}

#notice {
  color: #000 !important;
  border: 2px solid red;
  padding: 1em;
  margin-bottom: 2em;
  background-color: #f0f0f0;
  font: bold smaller sans-serif;
}

#columns {
  background: #141;

  #main {
    margin-left: 17em;
    padding: 1em;
    background: white;
  }

  #side {
    float: left;
    padding: 1em 2em;
    width: 13em;
    background: #141;

    ul {
      padding: 0;
      li {
        list-style: none;
        a {
          color: #bfb;
          font-size: small;
        }
      }
    }
  }
}

A continuación, agregamos la prueba de Storecontroller:

Modificar Test/Controller/store_controller_test.rb Archivo:
requiere 'test_helper' 

 Clase STORECONTROLLERTEST <ActionController :: Testcase 
   Prueba "debería obtener índice" hacer 
     Obtener: índice 
     Afirmar_Response: éxito 
 ASSERT_SELECT '#COLUMNS #SED A', MINIMUMS:

Luego ejecute la prueba funcional:

rake test:functionals

source

Random Posts

2019CCPC Jiangsu Nanjing Girls Championship | Solución de preguntas en línea

Comando de Linux para aprender Resumen: DOS2UNIX -UNIX2DOS ZIXIN Xuelian

HDU 1443 Joseph (problema de anillo de Joseph)

Win Conecte a MySQL de Linux Virtual Machine en Virtualbox

Servidor de correo de compilación de Linux