Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Creating the application

1,152 views

Published on

Agile Web Development with Rails Chapter 6

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Creating the application

  1. 1. Creating the Application
  2. 2. Creating a Rails application • rvm --create use 1.8.7@rails3 • rails new depot • cd depot • echo ‘rvm use 1.8.7@rails3’ >> .rvmrc • bundle install • rails generate scaffold Product title:string description:text image_url:string price:decimal
  3. 3. Rails Migration • db/migrate/2010031041958_create_products. rb (yours may vary)
  4. 4. Run Your DB Migrations • rake db:migrate – Creates the products table – Includes the fields we listed • rake db:rollback – Reverts last migration – Drops the products table
  5. 5. Let’s try it • rails server • http://localhost:3000/products – Create a new Product – Verify product was created – Reload /products to see list of products – Try deleting a product
  6. 6. Change view files • We want to change the number of lines in the description field to 6 • app/views/products/_form.html.erb – Change <%= f.text_area :description %> to <%= f.text_area :description, :rows => 6 %>
  7. 7. Run tests • rake test – You should see 0 failures, 0 errors – We’ll cover this more later
  8. 8. Add seed data to our DB • We don’t want to have to create test data manually all the time • Rails offers db/seeds.rb which will “seed” your database with test data • curl -o db/seeds.rb http://media.pragprog.com/titles/rails4/c ode/depot_b/db/seeds.rb
  9. 9. Grab book images and layout • http://media.pragprog.com/titles/rails4/code/d epot_b/public/images/ – Download each image and put it in public/images/ • curl -o public/stylesheets/depot.css http://media.pragprog.com/titles/rails4/code/d epot_b/public/stylesheets/depot.css • rm public/stylesheets/scaffold.css
  10. 10. Seed our database • rake db:seed – Runs content in db/seeds.rb • Reload /products to see our new “seed” books
  11. 11. Add stylesheet • System wide layout file • app/views/layouts/application.html.erb • <%= stylesheet_link_tag :all %>
  12. 12. app/views/products/index.html.erb
  13. 13. Push Depot to Heroku • Add Heroku to Gemfile • “bundle install” • heroku create • git push heroku master • heroku rake db:migrate • heroku rake db:seed • heroku open (add /products to URL)

×