Sub Resources Rails Plug-in2. RubyConf
Who I am
•Yasuko Ohba
•I love Ruby
•working with Ruby on
Rails
•CEO of Everyleaf
Corporation
株式会社万葉
2009年11月28日土曜日
4. RubyConf
Translating
This Book
株式会社万葉
2009年11月28日土曜日
5. RubyConf
Ruby on Rails
Quick Reference
株式会社万葉
2009年11月28日土曜日
6. RubyConf
The first
time
株式会社万葉
2009年11月28日土曜日
7. RubyConf
sub_resources
•a Rails plugin
• it extends
map.resources
株式会社万葉
2009年11月28日土曜日
8. RubyConf
github
http://
github.com/nay/
sub_resources
株式会社万葉
2009年11月28日土曜日
9. RubyConf
How many
people know
routes.rb ?
株式会社万葉
2009年11月28日土曜日
10. RubyConf
routes.rb
becomes messy
株式会社万葉
2009年11月28日土曜日
11. RubyConf
if you need
RESTful URLs
株式会社万葉
2009年11月28日土曜日
12. RubyConf
2 major
reasons
株式会社万葉
2009年11月28日土曜日
13. RubyConf
1. sub
resources in a
controller
株式会社万葉
2009年11月28日土曜日
14. RubyConf
what does
sub resources
mean?
株式会社万葉
2009年11月28日土曜日
15. RubyConf
examples
•Tags
• Notifications
• Images
株式会社万葉
2009年11月28日土曜日
16. RubyConf
tags
Book
Author
Tag Tagging
Review
株式会社万葉
2009年11月28日土曜日
17. RubyConf
How about
controllers?
株式会社万葉
2009年11月28日土曜日
18. RubyConf
you never
want this
•BooksTagsController
•AuthorsTagsController
• ReviewsTagsController
• etc...
株式会社万葉
2009年11月28日土曜日
19. RubyConf
instead
BooksController
TagService AuthorsController
ReviewsController
株式会社万葉
2009年11月28日土曜日
20. RubyConf
Not nice for
the regular
map.resources
株式会社万葉
2009年11月28日土曜日
21. RubyConf
Nested Resources ?
map.resources :books do |books|
books.resources :tags
end
株式会社万葉
2009年11月28日土曜日
22. RubyConf
use options of
map.resources ?
株式会社万葉
2009年11月28日土曜日
23. RubyConf
it generates
strange route
names
GET /books/3/tags
map.resources :books,
:member => {:tags => :get}
tags_book_path
株式会社万葉
2009年11月28日土曜日
24. RubyConf
it generates
urls including a
verb
DELETE /books/3/destroy_tag
map.resources :books, :member =>
{:destroy_tag => :delete}
destroy_tag_book_path
株式会社万葉
2009年11月28日土曜日
25. RubyConf
to fix this
map.book_tags 'books/:id/
tags', :controller => 'books', :action =>
'tags', :conditions => {:method => :get}
map.book_tag 'books/:id/
tag/:tag_id', :controller => 'books', :action
=> 'destroy_tag', :conditions => {:method
=> :delete}
株式会社万葉
2009年11月28日土曜日
26. RubyConf
for more actions,
more controllers
map.book_tags 'books/:id/tags', :controller => 'books', :action => 'tags', :conditions => {:method => :get}
map.book_tag 'books/:id/tag/:tag_id', :controller => 'books', :action => 'destroy_tag', :conditions =>
{:method => :delete}
map.edit_book_tags 'books/:id/tags/edit', :controller => 'books', :action => 'edit_tags', :conditions =>
{:method => :get}
map.connect 'books/:id/tas', :controller => 'books', :action => 'update_tags', :conditions => {:method
=> :put}
map.author_tags 'authors/:id/tags', :controller => 'authors', :action => 'tags', :conditions => {:method
=> :get}
map.author_tag 'authors/:id/tag/:tag_id', :controller => 'authors', :action => 'destroy_tag', :conditions =>
{:method => :delete}
map.edit_authors_tags 'books/:id/tags/edit', :controller => 'books', :action => 'edit_tags', :conditions =>
{:method => :get}
map.connect 'authors/:id/tas', :controller => 'authors', :action => 'update_tags', :conditions => {:method
=> :put}
map.author_tags 'reviews/:id/tags', :controller => 'reviews', :action => 'tags', :conditions => {:method
=> :get}
map.author_tag 'reviews/:id/tag/:tag_id', :controller => 'reviews', :action => 'destroy_tag', :conditions =>
{:method => :delete}
map.edit_book_tags 'reviews/:id/tags/edit', :controller => 'reviews', :action => 'edit_tags', :conditions =>
{:method => :get}
map.connect 'reviews/:id/tas', :controller => 'reviews', :action => 'update_tags', :conditions => {:method
=> :put} 株式会社 万葉
2009年11月28日土曜日
28. RubyConf
with
sub_resources
plugin
株式会社万葉
2009年11月28日土曜日
29. RubyConf
simple !
map.resources :books,
:sub_resources => :tags
株式会社万葉
2009年11月28日土曜日
30. RubyConf
nice mappings!
URL route name method action
GET tags
/books/:id/tags book_tags
POST create_tag
GET tag
/books/:id/tags/:tag_id book_tag PUT update_tag
DELETE destroy_tag
/books/:id/tags/new new_book_tag GET new_tag
/books/:id/tags/:tag_id/edit edit_book_tag DELETE edit_tag
株式会社 万葉
2009年11月28日土曜日
31. RubyConf
options available
map.resources :books,
:sub_resources => {
:tags => {
:only => [:index, :delete]
}
}
株式会社万葉
2009年11月28日土曜日
32. RubyConf
single style
map.resources :books,
:sub_resource => :image
株式会社万葉
2009年11月28日土曜日
33. RubyConf
2. update/
destroy
multiple records
at once
株式会社万葉
2009年11月28日土曜日
34. RubyConf
examples
株式会社万葉
2009年11月28日土曜日
35. RubyConf
edit_all
update_all
株式会社万葉
2009年11月28日土曜日
36. RubyConf
another
update_all
株式会社万葉
2009年11月28日土曜日
37. RubyConf
destroy_all
株式会社万葉
2009年11月28日土曜日
38. RubyConf
to delete all books
books
DELETE /books
destroy_all_books
DELETE /books/destroy_all
BooksController#destroy_all
株式会社万葉
2009年11月28日土曜日
39. RubyConf
with sub_resources
it s easy!
URL method action
/books/edit GET edit_all
/books PUT update_all
/books DELETE destroy_all
株式会社万葉
2009年11月28日土曜日
40. RubyConf
how to use
map.resources :books,
:collection => {
:edit_all => :get,
:update_all => :put,
:destroy_all => :delete
}
株式会社万葉
2009年11月28日土曜日
41. RubyConf
also available in
sub resources
URL name method action
/books/:id/tags/edit edit_book_tags GET edit_tags
/books/:id/tags PUT update_tags
book_tags
/books/:id/tags DELETE destroy_tags
株式会社 万葉
2009年11月28日土曜日
42. RubyConf
DELETE /books/3/tags
BooksController#destroy_tags
map.resources :books,
:sub_resources => {
:tags => {
:collection =>
{:destroy_all => :delete}
}
} 株式会社万葉
2009年11月28日土曜日
43. RubyConf
please try &
enjoy it!
http://
github.com/nay/
sub_resources
株式会社万葉
2009年11月28日土曜日