Model                Hamamatsurb#5 2011.07.13 @mackato2011   7   13
2011   7   13
Wiki                52011   7   13
2011   7   13
2011   7   13
2011   7   13
2011   7   13
Model                               - Ruby on Rails Guides                Rails Database Migrations: http://bit.ly/rrH5zQ ...
Version 1.9.2                             Version 3.0.7                .rvmrc                rvm ruby-1.9.2-p180@rails-3_0...
GitHub           git clone git://github.com/hamamatsu-rb/rails3dojo.git           git checkout -b working 2-model_pre2011 ...
FactoryGirl(             )   Spork(   )                           Gemfile                           .rspec                 ...
Wiki                User: Wiki                Page:                  Wiki                Comment: Page                Hist...
Wiki                 rails g model user name:string                 rake db:migrate2011   7   13
spec/factories.rb                spec/spec_helper.rb2011   7   13
spec/models/user_spec.rb2011   7   13
app/models/user.rb                                           SexyValidation!                 Legacy Style Validation2011  ...
bundle exec rspec spec/models/user_spec.rb                        User                          #name                     ...
Wiki                rails g model page title:string body:text                  user_id:integer                rake db:migr...
spec/factories.rb                spec/spec_helper.rb2011   7   13
spec/models/page_spec.rb(   )2011   7   13
app/models/page.rb2011   7   13
Page                rails g model comment body:text                  page_id:integer user_id:integer                rake d...
spec/factories.rb                spec/spec_helper.rb2011   7   13
spec/models/comment_spec.rb(   )2011   7   13
app/models/comment.rb2011   7   13
spec/models/page_spec.rb (   )                      app/models/page.rb2011   7   13
Page                rails g model history                 page_id:integer user_id:integer                rake db:migrate20...
spec/factories.rb                spec/spec_helper.rb2011   7   13
spec/models/history_spec.rb2011   7   13
app/models/history.rb2011   7   13
spec/models/page_spec.rb (   )                      app/models/page.rb2011   7   13
spec/models/page_spec.rb (   )                      app/models/page.rb2011   7   13
master                        git checkout master                        git merge working                        git bran...
2011   7   13
page           db/migrate/20110712154821_create_pages.rb                                                          rake db:...
Validation Helpers   vs   SexyValidation2011   7   13
The belongs_to Association                 The has_many :through Association        class  Order  <  ActiveRecord::Base   ...
Finder methods             Retrieving a Single Object                   •   where                   •   select            ...
2011   7   13
2011   7   13
2011   7   13
2011   7   13
Upcoming SlideShare
Loading in...5
×

浜松Rails3道場 其の弐 Model編

1,419

Published on

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

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

No notes for slide

浜松Rails3道場 其の弐 Model編

  1. 1. Model Hamamatsurb#5 2011.07.13 @mackato2011 7 13
  2. 2. 2011 7 13
  3. 3. Wiki 52011 7 13
  4. 4. 2011 7 13
  5. 5. 2011 7 13
  6. 6. 2011 7 13
  7. 7. 2011 7 13
  8. 8. Model - Ruby on Rails Guides Rails Database Migrations: http://bit.ly/rrH5zQ Active Record Validations and Callbacks: http://bit.ly/qp5vkm Active Record Associations: http://bit.ly/n3exu9 Active Record Query Interface: http://bit.ly/qaeazJ2011 7 13
  9. 9. Version 1.9.2 Version 3.0.7 .rvmrc rvm ruby-1.9.2-p180@rails-3_0_72011 7 13
  10. 10. GitHub git clone git://github.com/hamamatsu-rb/rails3dojo.git git checkout -b working 2-model_pre2011 7 13
  11. 11. FactoryGirl( ) Spork( ) Gemfile .rspec Spork spork --bootstrap2011 7 13
  12. 12. Wiki User: Wiki Page: Wiki Comment: Page History: Page2011 7 13
  13. 13. Wiki rails g model user name:string rake db:migrate2011 7 13
  14. 14. spec/factories.rb spec/spec_helper.rb2011 7 13
  15. 15. spec/models/user_spec.rb2011 7 13
  16. 16. app/models/user.rb SexyValidation! Legacy Style Validation2011 7 13
  17. 17. bundle exec rspec spec/models/user_spec.rb User #name 50 #find_or_create_by_name2011 7 13
  18. 18. Wiki rails g model page title:string body:text user_id:integer rake db:migrate2011 7 13
  19. 19. spec/factories.rb spec/spec_helper.rb2011 7 13
  20. 20. spec/models/page_spec.rb( )2011 7 13
  21. 21. app/models/page.rb2011 7 13
  22. 22. Page rails g model comment body:text page_id:integer user_id:integer rake db:migrate2011 7 13
  23. 23. spec/factories.rb spec/spec_helper.rb2011 7 13
  24. 24. spec/models/comment_spec.rb( )2011 7 13
  25. 25. app/models/comment.rb2011 7 13
  26. 26. spec/models/page_spec.rb ( ) app/models/page.rb2011 7 13
  27. 27. Page rails g model history page_id:integer user_id:integer rake db:migrate2011 7 13
  28. 28. spec/factories.rb spec/spec_helper.rb2011 7 13
  29. 29. spec/models/history_spec.rb2011 7 13
  30. 30. app/models/history.rb2011 7 13
  31. 31. spec/models/page_spec.rb ( ) app/models/page.rb2011 7 13
  32. 32. spec/models/page_spec.rb ( ) app/models/page.rb2011 7 13
  33. 33. master git checkout master git merge working git branch -d working GitHub git clone git://github.com/hamamatsu-rb/rails3dojo.git git checkout 2-model2011 7 13
  34. 34. 2011 7 13
  35. 35. page db/migrate/20110712154821_create_pages.rb rake db:migrate [VERSION=YY..] rake db:rollback [STEP=N] rake db:migrate:redo [STEP=N] page2011 7 13
  36. 36. Validation Helpers vs SexyValidation2011 7 13
  37. 37. The belongs_to Association The has_many :through Association class  Order  <  ActiveRecord::Base    belongs_to  :customer class  Physician  <  ActiveRecord::Base end    has_many  :appointments    has_many  :patients,  :through  =>  :appointments end The has_one Association   class  Appointment  <  ActiveRecord::Base class  Supplier  <  ActiveRecord::Base    belongs_to  :physician    has_one  :account    belongs_to  :patient end end   class  Patient  <  ActiveRecord::Base    has_many  :appointments The has_many Association    has_many  :physicians,  :through  =>  :appointments end class  Customer  <  ActiveRecord::Base    has_many  :orders end : Active Record Associations: http://bit.ly/n3exu92011 7 13
  38. 38. Finder methods Retrieving a Single Object • where • select • group • order Retrieving Multiple Objects • limit • offset • joins • includes • lock Calculations • readonly • from • having Active Record Query Interface: http://bit.ly/qaeazJ2011 7 13
  39. 39. 2011 7 13
  40. 40. 2011 7 13
  41. 41. 2011 7 13
  42. 42. 2011 7 13
  1. A particular slide catching your eye?

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

×