Your first rails app - 2

905 views
847 views

Published on

Slide #2 in a series of blazing cloud training for rails

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

  • Be the first to like this

No Downloads
Views
Total views
905
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Your first rails app - 2

  1. 1. YOUR FIRST RAILS APP Environments, MVC, ScaffoldSunday, November 13, 11
  2. 2. CREATING YOUR FIRST RAILS APP rails new roster This command generates code for a new Rails web application  in a sub-directory called “roster”  Sunday, November 13, 11
  3. 3. THE APPLICATION DIRECTORY • The whole rails app is in this one directory • No hidden configuration files in system directories • You will modify many of these files in the course of your development • Were using sqlite so even the database is in this directory, but usually the database is the only part of your application that lives somewhere else • You can simple copy this directory to server to deploy the app • You can delete the directory and its contents if you want to throw it away and start overSunday, November 13, 11
  4. 4. RUNNING YOUR APP cd roster bundle rails server Sunday, November 13, 11
  5. 5. RAILS ENVIRONMENTS By default, Rails is configured with 3 environments: • development • test • productionSunday, November 13, 11
  6. 6. RAILS ENVIRONMENTSSunday, November 13, 11
  7. 7. RAILS ENVIRONMENTSSunday, November 13, 11
  8. 8. RAILS ENVIRONMENTS The environment can be specified with RAILS_ENV as an environment variable "development" by default. In your code, you refer to Rails.env (or RAILS_ENV in Rails 2)Sunday, November 13, 11
  9. 9. CONFIG/DATABASE.YMLSunday, November 13, 11
  10. 10. ADDITIONAL CONFIGURATION config/environments/ • development.rb • production.rb • test.rbSunday, November 13, 11
  11. 11. MODIFYING THE HOME PAGE public/index.html All files in the public directory are static content. Rails checks this directory before executing any dynamic code.Sunday, November 13, 11
  12. 12. MVCSunday, November 13, 11
  13. 13. LEARNING WITH SCAFFOLD rails generate scaffold person first_name:string last_name:stringSunday, November 13, 11
  14. 14. NAMING CONVENTIONSSunday, November 13, 11
  15. 15. SCAFFOLD Model app/models/person.rb db/migrate/20090611073227_create_people.rb 5 views app/views/people/index.html.erb app/views/people/show.html.erb app/views/people/new.html.erb app/views/people/edit.html.erb app/views/people/_form.html.erb Controller app/controllers/people_controller.rb route.rb: resources :peopleSunday, November 13, 11
  16. 16. MVC Model: ActiveRecord •Represents what is in the database View: ActionView, erb •Model rendered as HTML Controller: ActionController •Receives HTTP actions (GET, POST, PUT, DELETE) •Decides what to do, typically rendering a viewSunday, November 13, 11
  17. 17. VIEWS <% @people.each do |person| %> <tr> <td><%= person.first_name %></td> <td><%= person.last_name %></td> </tr> <% end %>Sunday, November 13, 11
  18. 18. VIEW EXERCISE On the main people page  a. Change “Listing people” to “My Class List”  b. List people with first initial and last name in one visual column (e.g. W. Flintstone) Sunday, November 13, 11

×