rails basicsTuesday, May 28, 13
how dobrowsers work?Tuesday, May 28, 13
what does railsdo?Tuesday, May 28, 13
MODELS, Views, ControllersrMVC(and routes)Tuesday, May 28, 13
routerTuesday, May 28, 13
Tuesday, May 28, 13
Tuesday, May 28, 13
ROUTERthe router looks at the incoming requestand sends it to the right controller.Example:myapp.com/users/1/editgoes to t...
ROUTER/users users#index list all users/users/1 users#show show user with id 1/users/new users#new make a new user/users/1...
SAMPLE ROUTERedditDemo::Application.routes.draw	  do	  	  match	  users/	  =>	  users#index	  	  root	  to:	  users#indexe...
controllerTuesday, May 28, 13
Tuesday, May 28, 13
CONTROLLERThe controller orchestrates the request.It communicates with models to gatherand manipulate data.It then passes ...
CONTROLLER ACTIONSControllers have multiple actions.The standard ‘restful’ actions are:indexshowcreateneweditupdatedestroy...
SAMPLE CONTROLLERclass	  UsersController	  <	  ActionController::Base	  	  def	  index	  	  	  	  @users	  =	  User.all	  ...
modelsTuesday, May 28, 13
Tuesday, May 28, 13
MODELSModels represent the nouns and data inyour application.They make sure stored data is valid, andperform calculations/...
DATABASES•Store our model data (in rows), and define theattributes (columns).•We manage changes in our database with migra...
MIGRATION>> rails generate migration CreateUsersclass CreateUsers < ActiveRecord::Migrationdef changecreate_table :users d...
DATABASEid first_name last_name netid123Adam Bray alb64Vladimir The Bear vtb39Charlie The Horse cth44usersTuesday, May 28, 13
DATABASEid first_name last_name netid123Adam Bray alb64Vladimir The Bear vtb39Charlie The Horse cth44usersTuesday, May 28, 13
ADDING ANOTHER COLUMNrails generate migrationAddClassYearToUsers class_year:integerTuesday, May 28, 13
DATABASEid first_name last_name netid class_year123Adam Bray alb64 1995Vladimir The Bear vtb39 2015Charlie The Horse cth44 ...
SAMPLE MODELclass	  User	  <	  ActiveRecord::BaseendTuesday, May 28, 13
viewsTuesday, May 28, 13
Tuesday, May 28, 13
VIEWSViews are templates for how your webpages look.Variables created in the respectivecontroller are used to insert relev...
VIEWSViews use Embedded RuBy (ERB) tosubstitute data into the template.<% #ruby here is run, but not output %><%= #ruby he...
SAMPLE VIEW<%	  @users.each	  do	  |user|	  %>	  	  <%=	  user.name	  %><%	  end	  %>Tuesday, May 28, 13
Upcoming SlideShare
Loading in …5
×

Intro to rails

308 views

Published on

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

  • Be the first to like this

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

No notes for slide

Intro to rails

  1. 1. rails basicsTuesday, May 28, 13
  2. 2. how dobrowsers work?Tuesday, May 28, 13
  3. 3. what does railsdo?Tuesday, May 28, 13
  4. 4. MODELS, Views, ControllersrMVC(and routes)Tuesday, May 28, 13
  5. 5. routerTuesday, May 28, 13
  6. 6. Tuesday, May 28, 13
  7. 7. Tuesday, May 28, 13
  8. 8. ROUTERthe router looks at the incoming requestand sends it to the right controller.Example:myapp.com/users/1/editgoes to the users controller, edit action(and sends a ‘parameter’ for user_id=1 as )Tuesday, May 28, 13
  9. 9. ROUTER/users users#index list all users/users/1 users#show show user with id 1/users/new users#new make a new user/users/1/edit users#edit edit user with id 1Tuesday, May 28, 13
  10. 10. SAMPLE ROUTERedditDemo::Application.routes.draw  do    match  users/  =>  users#index    root  to:  users#indexendTuesday, May 28, 13
  11. 11. controllerTuesday, May 28, 13
  12. 12. Tuesday, May 28, 13
  13. 13. CONTROLLERThe controller orchestrates the request.It communicates with models to gatherand manipulate data.It then passes that data to the view.Tuesday, May 28, 13
  14. 14. CONTROLLER ACTIONSControllers have multiple actions.The standard ‘restful’ actions are:indexshowcreateneweditupdatedestroyTuesday, May 28, 13
  15. 15. SAMPLE CONTROLLERclass  UsersController  <  ActionController::Base    def  index        @users  =  User.all    endendTuesday, May 28, 13
  16. 16. modelsTuesday, May 28, 13
  17. 17. Tuesday, May 28, 13
  18. 18. MODELSModels represent the nouns and data inyour application.They make sure stored data is valid, andperform calculations/analysis.Tuesday, May 28, 13
  19. 19. DATABASES•Store our model data (in rows), and define theattributes (columns).•We manage changes in our database with migrations.Tuesday, May 28, 13
  20. 20. MIGRATION>> rails generate migration CreateUsersclass CreateUsers < ActiveRecord::Migrationdef changecreate_table :users do |t|t.string :first_namet.string :last_namet.string :netidt.timestampsendendendTuesday, May 28, 13
  21. 21. DATABASEid first_name last_name netid123Adam Bray alb64Vladimir The Bear vtb39Charlie The Horse cth44usersTuesday, May 28, 13
  22. 22. DATABASEid first_name last_name netid123Adam Bray alb64Vladimir The Bear vtb39Charlie The Horse cth44usersTuesday, May 28, 13
  23. 23. ADDING ANOTHER COLUMNrails generate migrationAddClassYearToUsers class_year:integerTuesday, May 28, 13
  24. 24. DATABASEid first_name last_name netid class_year123Adam Bray alb64 1995Vladimir The Bear vtb39 2015Charlie The Horse cth44 2016usersTuesday, May 28, 13
  25. 25. SAMPLE MODELclass  User  <  ActiveRecord::BaseendTuesday, May 28, 13
  26. 26. viewsTuesday, May 28, 13
  27. 27. Tuesday, May 28, 13
  28. 28. VIEWSViews are templates for how your webpages look.Variables created in the respectivecontroller are used to insert relevantinformation into the template.Tuesday, May 28, 13
  29. 29. VIEWSViews use Embedded RuBy (ERB) tosubstitute data into the template.<% #ruby here is run, but not output %><%= #ruby here is run and output %>Tuesday, May 28, 13
  30. 30. SAMPLE VIEW<%  @users.each  do  |user|  %>    <%=  user.name  %><%  end  %>Tuesday, May 28, 13

×