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

Ruby on Rails (the cool parts)

Ruby on Rails (the cool parts)

This is a presentation I gave that goes over "some" of the cool parts of Ruby on Rails.

Baylor Rae'

January 08, 2013
Tweet

Other Decks in Programming

Transcript

  1. %BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations class CreateProducts < ActiveRecord::Migration def up create_table :products

    do |t| t.string :title t.text :description t.decimal :price t.timestamps end end def down drop_table :products end end
  2. %BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations 1. add_column 2. add_index 3. change_column 4. change_table

    5. create_table 6. drop_table 7. remove_column 8. remove_index 9. rename_column
  3. %BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations 1. add_column :table_name, :column_name, :type 2. add_index, :table_name,

    :column_name 3. change_column :table_name, :column_name, :type 4. change_table :table_name, options = {} 5. create_table :table_name, options = {} 6. drop_table :table_name 7. remove_column :table_name, *columns 8. remove_index :table_name, *columns 9. rename_column :table_name, :old_name, :new_name
  4. %BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations $ rake db:migrate == CreateProducts: migrating ================================================= --

    create_table(:products) -> 0.0055s == CreateProducts: migrated (0.0056s) ======================================== == AddCategoryIdToProducts: migrating ======================================== -- add_column(:products, :category_id, :integer) -> 0.0015s == AddCategoryIdToProducts: migrated (0.0016s) ===============================
  5. %BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations db/schema.rb ActiveRecord::Schema.define(:version => 2013010801448284) do create_table "products", :force

    => true do |t| t.string "title" t.text "description" t.decimal "price" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.integer "category_id" end end
  6. 5IF"TTFU1JQFMJOF javascripts !"" bootstrap-dropdown.js !"" bootstrap-modal.js !"" bootstrap-popover.js !"" bootstrap-typeahead.js

    !"" content-tabs.js !"" lightbox.js !"" jquery-ui.js !"" jquery-ui.progress-bar.js !"" jquery.anything-slider.js !"" navigation-tabs.js #"" site.js http://bit.ly/asset-pipeline
  7. 5IF"TTFU1JQFMJOF javascripts !"" bootstrap-dropdown.js !"" bootstrap-modal.js !"" bootstrap-popover.js !"" bootstrap-typeahead.js

    !"" content-tabs.js !"" lightbox.js !"" jquery-ui.js !"" jquery-ui.progress-bar.js !"" jquery.anything-slider.js !"" navigation-tabs.js #"" site.js http://bit.ly/asset-pipeline
  8. . !"" app $ #"" assets $ !"" javascripts $

    #"" stylesheets !"" lib $ #"" assets $ !"" javascripts $ #"" stylesheets #"" vendor #"" assets !"" javascripts #"" stylesheets 5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline
  9. 5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline app/assets/js lib/assets/js vendor/assets/js !"" content-tabs.js #"" navigation-tabs.js !""

    bootstrap $ !"" dropdown.js $ !"" modal.js $ !"" popover.js $ #"" typeahead.js !"" bootstrap.js !"" lightbox.js !"" jquery-ui.js !"" jquery-ui.progress-bar.js #"" jquery.anything-slider.js #"" site.js
  10. 5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline app/assets/js lib/assets/js vendor/assets/js !"" content-tabs.js #"" navigation-tabs.js !""

    bootstrap $ !"" dropdown.js $ !"" modal.js $ !"" popover.js $ #"" typeahead.js !"" bootstrap.js !"" lightbox.js !"" jquery-ui.js !"" jquery-ui.progress-bar.js #"" jquery.anything-slider.js #"" site.js
  11. . #"" app #"" assets !"" javascripts/ #"" stylesheets/ 5IF"TTFU1JQFMJOF

    application.js application.css http://bit.ly/asset-pipeline
  12. 5IF"TTFU1JQFMJOF //= require jquery //= require jquery_ujs //= require bootstrap

    //= require_tree . /* *= require jquery-ui/datepicker *= require_self *= require_tree . */ application.js application.css http://bit.ly/asset-pipeline
  13. 5IF"TTFU1JQFMJOF $ rake assets:precompile . #"" app #"" assets !""

    javascripts/application.js #"" stylesheets/application.css http://bit.ly/asset-pipeline
  14. 5IF"TTFU1JQFMJOF public #"" assets !"" application-1b13569e9620782f423d4cd3ce931750.css !"" application-1b13569e9620782f423d4cd3ce931750.css.gz !"" application-32ed6ebaba49211fc69e08f40c7b97c4.js

    !"" application-32ed6ebaba49211fc69e08f40c7b97c4.js.gz !"" application.css !"" application.css.gz !"" application.js !"" application.js.gz !"" manifest.yml !"" rails-a3386665c05a2d82f711a4aaa72d247c.png #"" rails.png http://bit.ly/asset-pipeline
  15. 5IF"TTFU1JQFMJOF public #"" assets !"" application-1b13569e9620782f423d4cd3ce931750.css !"" application-1b13569e9620782f423d4cd3ce931750.css.gz !"" application-32ed6ebaba49211fc69e08f40c7b97c4.js

    !"" application-32ed6ebaba49211fc69e08f40c7b97c4.js.gz !"" application.css !"" application.css.gz !"" application.js !"" application.js.gz !"" manifest.yml !"" rails-a3386665c05a2d82f711a4aaa72d247c.png #"" rails.png http://bit.ly/asset-pipeline
  16. 5IF"TTFU1JQFMJOF public #"" assets !"" application-1b13569e9620782f423d4cd3ce931750.css !"" application-1b13569e9620782f423d4cd3ce931750.css.gz !"" application-32ed6ebaba49211fc69e08f40c7b97c4.js

    !"" application-32ed6ebaba49211fc69e08f40c7b97c4.js.gz !"" application.css !"" application.css.gz !"" application.js !"" application.js.gz !"" manifest.yml !"" rails-a3386665c05a2d82f711a4aaa72d247c.png #"" rails.png http://bit.ly/asset-pipeline
  17. #VJMEJOH8FC'PSNT http://bit.ly/rails-forms <form action="/products" method="post"> <!-- title --> <label for="title">Title</label>

    <input type="text" name="title" id="title" /> <!-- price --> <label for="price">Price</label> <input type="number" name="price" id="price" /> <!-- doo wop --> <input type="submit">Create Product</input> </form>
  18. #VJMEJOH8FC'PSNT http://bit.ly/rails-forms <%= form_for Product.new do |f| %> <!-- title

    --> <%= f.label :title %> <%= f.text_field :title %> <!-- price --> <%= f.label :price %> <%= f.number_field :price %> <!-- doo wop --> <%= f.submit %> <% end %>
  19. #VJMEJOH8FC'PSNT http://bit.ly/rails-forms <!-- title --> <label for="product_title">Title</label> <input type="text" name="product[title]"

    id="product_title" /> <!-- price --> <label for="product_price">Price</label> <input type="number" name="product[price]" id="product_price" />
  20. #VJMEJOH8FC'PSNT http://bit.ly/rails-forms <!-- title --> <label for="product_title">Title</label> <input type="text" name="product[title]"

    id="product_title" /> <!-- price --> <label for="product_price">Price</label> <input type="number" name="product[price]" id="product_price" />
  21. #VJMEJOH8FC'PSNT http://bit.ly/rails-forms class ProductsController < ApplicationController # POST /products def

    create @products = Product.new(product_params) end private def product_params params.require(:product).permit(:title, :price) end end
  22. #VJMEJOH8FC'PSNT http://bit.ly/rails-forms <%= form_for @product do |f| %> <ul> <%=

    f.fields_for :product_variations do |builder| %> <li> <%= builder.label :title %> <%= builder.text_field :title %> <br /> <%= builder.label :price, "$" %> <%= builder.number_field :price %> </li> <% end %> </ul> <% end %>