Advertisement
KevinPerez

PC-01-Ruby

May 4th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 4.70 KB | None | 0 0
  1. ====================== SETUP PROJECT ====================
  2. --- Step 1 Ambiente=> terminal
  3. gem install rails --version=4.2.6
  4. rails new bscatapp -d mysql
  5. cd bscatapp/
  6. sudo service mysql start
  7. rake db:create
  8.  
  9. --- Step 2 Ambiente=> Edición de archivo
  10. -- Abrir el archivo Gemfile ubicado en la raiz del proyecto y en la linea depues de 'spring', no se olvide de grabar
  11. # Twitter Bootstrap Fronted Framework Support
  12. gem 'therubyracer'
  13. gem 'less-rails'
  14. gem 'twitter-bootstrap-rails', '<= 3.2.0'
  15. # Simplified HTML Form Management
  16. gem 'simple_form'
  17. # Authentication Support
  18. gem 'devise'
  19. gem 'devise-bootstrap-views'
  20. # Entitites Admin Support
  21. gem 'rails_admin'
  22. ====================== DEVELOPING PROJECT ====================
  23. --- Step 3: Ambiente=> terminal
  24. bundle
  25. rails g controller pages index about_us tos faq contact_us
  26. rails g bootstrap:install static
  27. rails g simple_form:install —bootstrap
  28. rails g devise:install
  29. rails g devise User
  30. a
  31. rails g scaffold Category name:string description:text
  32. rake db:migrate
  33. rails g bootstrap:themed categories
  34. a
  35. rails g scaffold Product name:string description:text category:references
  36. rake db:migrate
  37. rails g bootstrap:themed products
  38. a
  39. rails g scaffold Person first_name:string last_name:string
  40. rake db:migrate
  41. rails g bootstrap:themed people
  42. a
  43. rails g scaffold Warehouse name:string location:text
  44. rake db:migrate
  45. rails g bootstrap:themed warehouses
  46. a
  47. rails g scaffold Inventory warehouse:references product:references stock:integer
  48. rake db:migrate
  49. rails g bootstrap:themed inventories
  50. a
  51. rake routes
  52.  
  53. --- Step 4: Ambiente=> Crear y editar archivo de archivo
  54. -- Crear los dos siguientes archivos en: proyecto\app\views\layouts
  55.     _menu.html.erb
  56.     _auth.html.erb
  57. -- Abrir el archivo _menu.html.erb, pegar el siguiente código y grabar:
  58.     <li><%= link_to "Home", pages_index_path  %></li>
  59.     <% if current_user %>
  60.         <li><%= link_to "Categories", categories_path %></li>
  61.         <li><%= link_to "Warehouses", warehouses_path %></li>
  62.         <li><%= link_to "Inventories", inventories_path %></li>
  63.         <li><%= link_to "Products", products_path %></li>
  64.     <% end %>
  65.     <li><%= link_to "About us", pages_about_us_path  %></li>
  66.     <li><%= link_to "Terms of Services", pages_tos_path  %></li>
  67.     <li><%= link_to "FAQ", pages_faq_path  %></li>
  68.     <li><%= link_to "Contact Us", pages_contact_us_path  %></li>
  69.  
  70. -- Abrir el archivo _auth.html.erb, pegar el siguiente código y grabar:
  71.  
  72.     <p class="navbar-text navbar-right">
  73.         <% if current_user %>
  74.             Signed in as <a href="#" class="navbar-link"> <%= current_user.email %></a>
  75.             <%= link_to 'Sign out', destroy_user_session_path, method: :delete %>
  76.         <% else %>
  77.             <%= link_to 'Sign In', new_user_session_path %> or
  78.             <%= link_to 'Sign Up', new_user_registration_path %>
  79.         <% end %>
  80.     </p>
  81.  
  82. -- Abrir el archivo application.html.erb, y buscar las dos veces que se repite lo siguiente
  83. -Reemplazar:
  84.     <li><%= link_to "Link1", "/path1"  %></li>
  85.     <li><%= link_to "Link2", "/path2"  %></li>
  86.     <li><%= link_to "Link3", "/path3"  %></li>
  87. -por:
  88.     <%= render 'layouts/menu' %>
  89. - Encima de la siguiente línea de código agregar:
  90.     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
  91. - Lo siguiente
  92.     <%= render 'layouts/auth' %>
  93.  
  94. --- Step 5: Ambiente=> Editar archivos capa models: proyecto\app\models, agregar arriba de "end"
  95. -\category.rb
  96.   has_many :products
  97.  
  98. -\inventory.rb
  99.   belongs_to :warehouse
  100.   belongs_to :product
  101.  
  102. -\product.rb
  103.   belongs_to :category
  104.   has_many :inventories
  105.   has_many :warehouses, through: :inventories
  106.  
  107. -\warehouse.rb
  108.   has_many :inventories
  109.   has_many :products, through:  :inventories
  110.  
  111. --- Step 6: Ambiente=> Editar archivos
  112. -- Abrir el archivo: proyecto\app\views\products\index.html.erb
  113.  
  114. -Reemplazar:
  115.     <th><%= model_class.human_attribute_name(:category_id) %></th>
  116. -Por:
  117.     <th><%= model_class.human_attribute_name(:category_id) %></th>
  118.     <th><%= model_class.human_attribute_name(:warehouses) %></th>
  119. -Reemplazar:
  120.     <td><%= product.category_id %></td>
  121. -Por:
  122.     <td><%= product.category.name %></td>
  123.     <td><%= product.warehouses.count %></td>
  124.  
  125. -- Abrir el archivo: proyecto\app\views\categories\index.html.erb  
  126.  
  127. -Reemplazar:
  128.     <th><%= model_class.human_attribute_name(:description) %></th>
  129. -Por:
  130.     <th><%= model_class.human_attribute_name(:description) %></th>
  131.     <th><%= model_class.human_attribute_name(:products) %></th>
  132. -Reemplazar:
  133.     <td><%= category.description %></td>
  134. -Por:
  135.     <td><%= category.description %></td>
  136.     <td><%= category.products.count %></td>
  137.  
  138.  
  139. --- Step 7: Ambiente=> Edición de archivo
  140. -- Abrir el archivo tu_proyecto\config\routes.rb, ubicarse en la línea 2, no se olvide de grabar
  141. root 'pages#index'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement