Creating the Application
Creating a Rails application
• rvm --create use 1.8.7@rails3
• rails new depot
• cd depot
• echo ‘rvm use 1.8.7@rails3’ >>...
Rails Migration
• db/migrate/2010031041958_create_products.
rb (yours may vary)
Run Your DB Migrations
• rake db:migrate
– Creates the products table
– Includes the fields we listed
• rake db:rollback
–...
Let’s try it
• rails server
• http://localhost:3000/products
– Create a new Product
– Verify product was created
– Reload ...
Change view files
• We want to change the number of lines
in the description field to 6
• app/views/products/_form.html.er...
Run tests
• rake test
– You should see 0 failures, 0 errors
– We’ll cover this more later
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...
Grab book images and layout
• http://media.pragprog.com/titles/rails4/code/d
epot_b/public/images/
– Download each image a...
Seed our database
• rake db:seed
– Runs content in db/seeds.rb
• Reload /products to see our new “seed”
books
Add stylesheet
• System wide layout file
• app/views/layouts/application.html.erb
• <%= stylesheet_link_tag :all %>
app/views/products/index.html.erb
Push Depot to Heroku
• Add Heroku to Gemfile
• “bundle install”
• heroku create
• git push heroku master
• heroku rake db:...
Upcoming SlideShare
Loading in...5
×

Creating the application

1,026

Published on

Agile Web Development with Rails Chapter 6

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,026
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×