-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Collection Routing for Rails #15719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collection Routing for Rails #15719
Conversation
This is more of a test to understand that wether I'm on the right track!
:replace_all is now :replace and other *_all methods are now *_many
Renamed the :bulk option to :collection
Merged put, patch and delete into a single if Created a small utility method collection_routing to check if the Resource is a collection too
Added a flag to Resource to mark collection_routing.
Now collection routing path generations matches the regular path generation flow.
If a range is detected then illegal values are removed from the final array of ranges and integers.
…ular resourceful routes.
…lly for individual resources.
Forgot to track it previously.
The API makes sure that the parameter values lie within the given given range.
If you provide range while permitting a parameter then all comma separated values passed as the parameter should lie within that range.
Added some tests for strong parameters. Yet to be tested.
… parameters and reverse ranges.
…ith appropriate messages. Had wrongly used assert instead of assert_equal in 75ae0e
…edit_many to :edit
Need to think more about the need for :show_many and what url helpers will it generate since it's just a special case of :index.
Checks wether routing to :index happens without :ids parameter.
I agree that we don't have a solid convention here that'll just work for most people most of the time. I've done collection routes myself quite a few times and never found that magical line that leads to extraction. 👍 on closing. Thanks for all the work exploring this.
|
Thank you so much for the work on this. |
Actually, I just had to do yet another set of bulk controllers in the past week, and I'm thinking we can get a lot of bang for just a few bucks by focusing on just the routing part, and just focus on the comma-separated list. Here's a proposal that also unifies the naming around "bulk": resources :posts, bulk: true
class PostsController
# GET /posts/1,4,5
def show_bulk
end
# GET /posts/1,4,5/edit
def edit_bulk
end
# PATCH/PUT /posts/1,4,5
def update_bulk
end
# DELETE /posts/1,4,5
def destroy_bulk
end
end |
@dhh: I can make those changes and push them in a couple of days. What say?
|
I'd be happy to review that, Ujjwal. I think part of the problem here was On Fri, Apr 24, 2015 at 3:16 PM, Ujjwal Thaakar notifications@github.com
|
@dhh How would you handle creating many records? Would it be |
I was just thinking about that one too. I do think it makes sense to add On Fri, Apr 24, 2015 at 3:36 PM, Wojciech Wnętrzak <notifications@github.com
|
In fact, in my own use, I've actually also needed GET /posts/new_bulk => On Fri, Apr 24, 2015 at 3:37 PM, David Heinemeier Hannson <
|
@dhh I'd like to understand your use case especially why you needed a bulk route for |
You mean new_bulk? It's the difference between a place where you create 1 thing at the time vs stuff in bulk. Think 1 todo item vs 10 todo items at the time. |
No I meant why can't you use the same route for both like I have
|
Because you want to use different setup and different templates depending on whether it's bulk or not. Just like all the others. |
But we direct them to different actions they'll always tender into
|
I don't understand what you mean? I'm saying that /posts/new_bulk would be On Fri, Apr 24, 2015 at 7:48 PM, Ujjwal Thaakar notifications@github.com
|
Oh I misunderstood. My bad.
|
Then what is it that is the same that makes it better to keep in one controller rather than a controller dedicated to a collection resource? This seems likely to head to a lot of divergent code in a controller:
Additionally, the idea of a |
Derek, this is a spectrum. I most often have controllers that have 1 or 2 You can definitely split out a bulk controller as well too, if you like. I Also, show_many is not the same as index in my use cases. Showing a couple On Fri, Apr 24, 2015 at 7:56 PM, Derek Prior notifications@github.com
|
@rafaelfranca Please reopen the PR. I'll implement a lean solution and take this one feature at a time with full consensus before me merge. |
@dhh: I think collection is a better term than bulk. Personally I prefer Regarding your last point. Don't you think |
I don't like collection because we already use that term to refer "all the things", as in index/new/create and with routing via collection do/end. Bulk is a new term we can define to mean "some of the things". I don't like reusing index either. The whole point of this feature is to split one from some from all and give each their own actions.
|
I prefer update_bulk such that it can be listed under update and follow a On Sat, Apr 25, 2015 at 9:47 PM, Matthew Draper notifications@github.com
|
@matthewd Hmmm, ok let me see if I can quickly build something and open a new PR. But don't you think we should continue with this PR only since it has all the discussion. Or do you feel it's already too big? |
@dhh Do we want to route both PUT and PATCH to update_bulk. This was one of the points originally where we wanted two separate actions. PUT completes replaces the collection while PATCH only modifies certain resources. |
I'd route both to the same like we do for regular update for now to stay On Saturday, June 6, 2015, Ujjwal Thaakar notifications@github.com wrote:
|
As part of Google Summer of Code 2013, I worked on implementing a collection routing api for Rails under the mentorship of @pixeltrix.
Majority of the work is over with enough stability to be considered for merging. I would like to open up the discussion on the api. The documentation still remains but this is on purpose considering the community might vote for changes.
Features
Generate collection routes by including a collection option.
Pass ranges as parameters and filter them using the Strong Parameters API
Ranges can now be passed as url parameters. Following are some examples :-
Generate collection routing enabled controllers using scaffolds
rails generate scaffold Posts --collection
Scaffold generators of dependencies like JBuilder need to be updated to incorporate collection routing.
Future work will include reducing
replace
andupdate_many
to single line atomic database operations using ActiveRecord.