Slide 1

Slide 1 text

Collection Routing in Rails 5 ? claudiob.github.io

Slide 2

Slide 2 text

TL;DR DELETE "/posts/1" PostsController#destroy id: 1 DELETE "/posts/4" PostsController#destroy id: 4 Rails 4 DELETE "/posts/1,4" PostsController#destroy_many ids: [1,4] Rails 5 Task: delete many posts in a blog ? 2/12

Slide 3

Slide 3 text

Rails 5 TL;DR Task: ______ many posts in a blog PATCH "/posts/1..2" PostsController#update_many ids: [1,2] GET "/posts/1..3,5" PostsController#index ids: [1,2,3,5] DELETE "/posts/1,4" PostsController#destroy_many ids: [1,4] ? 3/12

Slide 4

Slide 4 text

TL;DR Task: ______ many posts in a blog PATCH "/posts/1..2" PostsController#update_many ids: [1,2] GET "/posts/1..3,5" PostsController#index ids: [1,2,3,5] DELETE "/posts/1,4" PostsController#destroy_many ids: [1,4] Not in Rails 5 4/12

Slide 5

Slide 5 text

May 2011 class PostsController < ActiveController::Base # PUT /posts/1,4,50,90 def update_many @posts = Post.find params[:ids] Post.transaction do @posts.each do |post| post.update! params[:posts][post.id] end end end end gist.github.com/dhh/981520 5/12

Slide 6

Slide 6 text

June 2013 Regexp? Method names? Generators? Actions? Ranges? github.com/ujjwalt/rails/pull/1 6/12

Slide 7

Slide 7 text

June 2014 github.com/rails/rails/pull/15719 Transactions? JSON API? Nested routes? Views? 7/12

Slide 8

Slide 8 text

February 2015 gist.github.com/claudiob/34f610b240a3fec364ae Let’s try to extract a single change from the PR GET "/posts/1,3,4" PostsController action: show id: "1,3,4" PostsController action: index ids: ["1", "3", "4"] Is this better than a filter? 8/12

Slide 9

Slide 9 text

February 2015 gist.github.com/claudiob/34f610b240a3fec364ae Let’s try to extract a single change from the PR GET "/posts?ids[]=1&ids[]=3&ids[]=4" PostsController action: index ids: ["1", "3", "4"] When would the query cache expire? 9/12

Slide 10

Slide 10 text

February 2015 gist.github.com/claudiob/34f610b240a3fec364ae Let’s try to extract a single change from the PR DELETE "/posts?ids[]=1&ids[]=3&ids[]=4" PostsController action: destroy id: "1,3,4" PostsController action: destroy_many ids: ["1", "3", "4"] Would this cause confusion? 10/12

Slide 11

Slide 11 text

March 2015 Rails 5.0 Basecamp Perfect example of how something that seems “obvious” isn’t always so. I’ve yet to find any collection logic in my apps that would work well as an extraction. There always seems to be app-specific wriggles to contend with, and the code isn’t really complex in any case. I vote to not include this in core. 11/12

Slide 12

Slide 12 text

Summing up No collection routing in Rails 5 github.com/arsduo/batch_api There is a gem for that™ Questions? Thanks!