monterrey, nuevo león · w. ukko.mx m. [email protected] t. (81) 2315 4497 av. del estado 120 colonia...
TRANSCRIPT
W. ukko.mxM. [email protected]. (81) 2315 4497
Av. del Estado 120Colonia Tecnológico,Monterrey, Nuevo León
●
●
●
* FUENTE: HTTPS://WWW.RUBY-LANG.ORG
class Numeric
def plus(x)
self.+(x)
end
end
y = 5.plus 6
# y is now equal to 11
5.times { print “We *love* Ruby -- it’s outrageous!” }
* FUENTE: HTTPS://WWW.RUBY-LANG.ORG
* FUENTE: WWW.SLANT.COM
xcode-select --installsudo xcodebuild -licenseruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install rbenv ruby-build
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profilesource ~/.bash_profile
rbenv install 2.6.3rbenv global 2.6.3ruby -v
sudo gem install railsrbenv rehash
rails new inventory
.. (up a dir)/users/ikernarvaez/development/ukko/curso/> app/> bin/> config/> db/> lib/> log/> public/> storage/> test/> tmp/> vendor/ config.ru Gemfile Gemfile.lock package.json Rakefile README.md
●
●
gem install bundler
bundle install
●
●
gem install bundler
bundle install
●
○
○
○
rails server
localhost:3000
●
●
●
○
○
●
○
rails generate model Product name:string quantity:integer description:string price:float
rake db:migrate
== 20190715233750 CreateProducts: migrating ==========================================================-- create_table(:products) -> 0.0016s== 20190715233750 CreateProducts: migrated (0.0017s) =================================================
root to: ‘products#index’
resources :products
class ProductsController < ApplicationController
def index
@products = Product.all
end
end
1. <div>2. <%= link_to 'Agregar Producto', new_product_path %>3. </div>4.5. <table>6. <thead>7. <th> Nombre </th>8. <th> Cantidad </th>9. <th> Descripción </th>10. <th> Precio </th>11. </thead>12. <tbody>13. <% @products.each do |p| %>14. <tr>15. <td><%= p.name %></td>16. <td><%= p.quantity %></td>17. <td><%= p.description %></td>18. <td><%= p.price %></td>19. </tr>20. <% end %>21. </tbody>22. </table>
class ProductsController < ApplicationController
def index
@products = Product.all
end
def new
@product = Product.new
end
end
<%= form_for @product do |f|%>
Nombre: <%= f.text_field :name %>
Descripción: <%= f.text_field :description %>
Cantidad: <%= f.number_field :quantity %>
Precio: <%= f.number_field :price %>
<%= f.submit 'Guardar' %>
<% end %>
class ProductsController < ApplicationController def index @products = Product.all end def new @product = Product.new end def create @product = Product.new(object_params) @product.save redirect_to products_path end private def object_params params.require(:product).permit(:description, :quantity, :price) endend
●
●
HINT: USAR ACTIVE STORAGE
W. ukko.mxM. [email protected]. (81) 2315 4497
Av. del Estado 120Colonia Tecnológico,Monterrey, Nuevo León