Intro to Rails Give Camp Atlanta
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Intro to Rails Give Camp Atlanta

  • 2,654 views
Uploaded on

A presentation detailing building a Rails shopping cart from scratch

A presentation detailing building a Rails shopping cart from scratch

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,654
On Slideshare
2,652
From Embeds
2
Number of Embeds
2

Actions

Shares
Downloads
6
Comments
0
Likes
0

Embeds 2

http://www.linkedin.com 1
https://www.linkedin.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • heroku create _NAME_ will create an app called _NAME_, i.e. http://_NAME_.heroku.com
  • Modifying the specified line to include the :precision and :scale arguments.rake db:migrate executes this code to create the products tableThe scaffolding will now be available at http://localhost:3000/products
  • When you go to /products and click New ProductWhen you submit a product that fails validation, rails automatically generates the error page shown

Transcript

  • 1. Intro to Ruby on Rails
    Jason Noble
    http://jasonnoble.org
    Alan Hecht
    http://alanhecht.me
  • 2. Slides are available
    http://slideshare.net/jasonjnoble/
    Intro to Rails Give Camp Atlanta
    Finished code is also available
    https://github.com/jasonnoble/givecampatl-rails-demo
  • 3.
  • 4. History
    Initial Release July 2004
    Written by David Heinemeier Hansson
    Rails 3.0 released August 29, 2010
  • 5. Technical Overview
    Model-View-Controller (MVC) architecture
    Includes scaffolding to automatically construct the models and views needed for a basic site
    Includes WEBrick, a simple Ruby web server
    Includes Prototype and Script.aculo.us JavaScript libraries for Ajax
    RESTful web services used instead of SOAP
    Handles HTML and XML output out of the box
  • 6. Framework Structure
    ActiveRecord – Object relational mapping system for database access
    ActiveResource -- Web Services
    ActionPack
    ActiveSupport
    ActionMailer
    Lots of plugins available
  • 7. Philosophy
    Convention over Configuration
    Decreases decisions that developers need to make
    By doing things the “standard” way it just works
    Don’t Repeat yourself (DRY)
    Every piece of code has a single, unambiguous authoritative representation within a system
    Modifying any single element does not change other logically-unrelated elements
    Use methods and subroutines to abstract out pieces of code called in multiple places
  • 8. Installing
    Install Ruby and RubyGems
    Gems are a Ruby package format
    gem install rails
    Rails works with SQLite out of the box
    MySQL, PostgreSQL, Oracle, MS SQL gems available
  • 9. Installing Rails
    Windows
    http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-windows
    OS X
    http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac
    Linux
    Most of http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac will work
  • 10. Let’s build a shopping cart
    rails new demo_app
    vi demo_app/.rvmrc
    rvm –create use 1.9.2@rails3
    cd demo_app
    rails server
    http://localhost:3000
    gitinit .
    git add .
    git commit –m ‘Initial rails app’
  • 11. Push App to Heroku
    vi Gemfile
    Add “gem heroku” line
    bundle install
    heroku create
    git push –u heroku master
    heroku open
  • 12. Product Scaffolding
    Add a CRUD (create, read, update, delete) interface
    rails generate scaffold Product title:stringdescription:textimage_url:stringprice:decimal
    creates db/migrate/20110108190442_create_products.rb
  • 13. db/migrate/2011010819_create_products.rb
    Filename is date/time specific, so yours may differ
    Adding precision and scale to price field
    rake db:migrate
    http://localhost:3000/products
  • 14. Modifying the view
    app/views/products/_form.html.erb
    Views are dynamically rendered, so reloading in your browser will show your updates
  • 15. Seeding your DB with data
    db/seeds.rb
    Executes Ruby code to pre-populate your database
    Good way to start with sample data
    rake db:seed
    Runs the ruby code
  • 16. Update Products View
    app/views/products/index.html.erb
  • 17. Push to Heroku
    git add .
    git commit –m ‘Products scaffold’
    git push heroku
    heroku rake db:migrate
    heroku rake db:seed
    heroku open
    add a /products to the URL
  • 18. Data Validation
    Rails has data validation built into the model
    app/models/product.rb
  • 19. Data Validation (cont.)
  • 20. Rails Testing
    rake test
    Runs all the built in Rails tests
    Prints Failures as it finds them, but continues
  • 21. Functional Tests
    Tests Controller actions
    test/functional/products_controller_test.rb
  • 22. Unit Tests
    Tests Model methods/attributes/validations
    test/unit/product_test.rb
  • 23. Push to Heroku
    git add .
    git commit –m ‘Added validation’
    git push heroku
  • 24. Store Front
    rails generate controller store index
    http://localhost:3000/store/index
    gitrm public/index.html
    config/routes.rb
    http://localhost:3000/
  • 25. Store Controller
    Modify store controller to pull products from the database
    app/controllers/store_controller.rb
  • 26. View file changes
    app/views/store/index.html.erb
  • 27. Application Layout
    app/views/layouts/application.html.erb
  • 28. Updated view
  • 29. Customer wants books alphabatized
    app/models/product.rb
  • 30. Store Functional Test
    test/functional/store_controller_test.rb
  • 31. Push to Heroku
    git add .
    git commit –m ‘Store scaffold’
    git push heroku
    heroku open
  • 32. Cart Scaffold
    rails generate scaffold cart
    rake db:migrate
  • 33. Modify Application Controller
    app/controller/application_controller.rb
  • 34. LineItems scaffold
    rails generate scaffold line_itemproduct_id:integercart_id:integerquantity:integer
  • 35. Update Cart model
    app/models/cart.rb
  • 36. Update LineItem Model
    app/models/line_item.rb
  • 37. Update Product model
    app/models/product.rb
  • 38. Add to Cart button
    app/views/store/index.html.erb
  • 39. LineItems controller
    app/controllers/line_items_controller.rb
  • 40. Carts View
    app/views/carts/show.html.erb
  • 41. Carts Controller
    app/controller/carts_controller.rb
  • 42. Update Heroku
    git add .
    git commit –m ‘Cart updated’
    git push heroku
    heroku open
  • 43. Further Reading
    Agile Web Development with Rails
    http://pragprog.com/titles/rails4/agile-web-development-with-rails
    http://rubyonrails.org