sub resources rails plug-in
DESCRIPTION
The presentation in LT of RubyConf2009 about sub_resources rails plug-in.http://github.com/nay/sub_resourcesTRANSCRIPT
sub_resourcesRails PluginYasuko Ohba
@nay3
2009年11月28日土曜日
株式会社万葉
RubyConf
Who I am•Yasuko Ohba•I love Ruby•working with Ruby on Rails
•CEO of Everyleaf Corporation
2009年11月28日土曜日
Everyleaf Corporation
2009年11月28日土曜日
株式会社万葉
RubyConf
Translating This Book
2009年11月28日土曜日
株式会社万葉
RubyConf
Ruby on RailsQuick Reference
2009年11月28日土曜日
株式会社万葉
RubyConf
The first time
2009年11月28日土曜日
株式会社万葉
RubyConf
sub_resources
•a Rails plugin•it extends map.resources
2009年11月28日土曜日
株式会社万葉
RubyConf
github
http://github.com/nay/sub_resources
2009年11月28日土曜日
株式会社万葉
RubyConf
How many people know routes.rb ?
2009年11月28日土曜日
株式会社万葉
RubyConf
routes.rbbecomes messy
2009年11月28日土曜日
株式会社万葉
RubyConf
if you needRESTful URLs
2009年11月28日土曜日
株式会社万葉
RubyConf
2 major reasons
2009年11月28日土曜日
株式会社万葉
RubyConf
1. sub resources in a controller
2009年11月28日土曜日
株式会社万葉
RubyConf
what does ‘sub resources’
mean?
2009年11月28日土曜日
株式会社万葉
RubyConf
examples
•Tags•Notifications•Images
2009年11月28日土曜日
株式会社万葉
RubyConf
tags
Tag
Review
Author
Book
Tagging
2009年11月28日土曜日
株式会社万葉
RubyConf
How aboutcontrollers?
2009年11月28日土曜日
株式会社万葉
RubyConf
you never want this
•BooksTagsController•AuthorsTagsController•ReviewsTagsController•etc...
2009年11月28日土曜日
株式会社万葉
RubyConf
instead
BooksController
AuthorsController
ReviewsController
TagService
2009年11月28日土曜日
株式会社万葉
RubyConf
Not nice forthe regular
map.resources
2009年11月28日土曜日
株式会社万葉
RubyConf
Nested Resources ?
map.resources :books do |books| books.resources :tagsend
2009年11月28日土曜日
株式会社万葉
RubyConf
use options of map.resources ?
2009年11月28日土曜日
株式会社万葉
RubyConf
it generatesstrange route
namesmap.resources :books, :member => {:tags => :get}
tags_book_path
GET /books/3/tags
2009年11月28日土曜日
株式会社万葉
RubyConf
it generatesurls including a
verb
destroy_tag_book_path
DELETE /books/3/destroy_tag
map.resources :books, :member => {:destroy_tag => :delete}
2009年11月28日土曜日
株式会社万葉
RubyConf
to fix thismap.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日土曜日
株式会社万葉
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.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.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 '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.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}
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}
2009年11月28日土曜日
株式会社万葉
RubyConf
2009年11月28日土曜日
株式会社万葉
RubyConf
with sub_resources
plugin
2009年11月28日土曜日
株式会社万葉
RubyConf
simple !
map.resources :books, :sub_resources => :tags
2009年11月28日土曜日
株式会社万葉
RubyConf
nice mappings!URL route name method action
/books/:id/tags book_tagsGET tags
/books/:id/tags book_tagsPOST create_tag
/books/:id/tags/:tag_id book_tag
GET tag
/books/:id/tags/:tag_id book_tag PUT update_tag/books/:id/tags/:tag_id book_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日土曜日
株式会社万葉
RubyConf
options availablemap.resources :books, :sub_resources => { :tags => { :only => [:index, :delete] } }
2009年11月28日土曜日
株式会社万葉
RubyConf
single style
map.resources :books, :sub_resource => :image
2009年11月28日土曜日
株式会社万葉
RubyConf
2. update/destroy
multiple recordsat once
2009年11月28日土曜日
株式会社万葉
RubyConf
examples
2009年11月28日土曜日
株式会社万葉
RubyConf
edit_allupdate_all
2009年11月28日土曜日
株式会社万葉
RubyConf
another update_all
2009年11月28日土曜日
株式会社万葉
RubyConf
destroy_all
2009年11月28日土曜日
株式会社万葉
RubyConf
to delete all booksbooks
DELETE /books
BooksController#destroy_all
DELETE /books/destroy_alldestroy_all_books
2009年11月28日土曜日
株式会社万葉
RubyConf
with sub_resourcesit’s easy!
URL method action
/books/edit GET edit_all
/books PUT update_all
/books DELETE destroy_all
2009年11月28日土曜日
株式会社万葉
RubyConf
how to usemap.resources :books, :collection => { :edit_all => :get, :update_all => :put, :destroy_all => :delete }
2009年11月28日土曜日
株式会社万葉
RubyConf
also available in sub resources
URL name method action
/books/:id/tags/edit edit_book_tags GET edit_tags
/books/:id/tagsbook_tags
PUT update_tags
/books/:id/tagsbook_tags
DELETE destroy_tags
2009年11月28日土曜日
株式会社万葉
RubyConf
DELETE /books/3/tags
map.resources :books, :sub_resources => { :tags => { :collection => {:destroy_all => :delete} } }
BooksController#destroy_tags
2009年11月28日土曜日
株式会社万葉
RubyConf
please try & enjoy it!
http://github.com/nay/sub_resources
2009年11月28日土曜日