-
Notifications
You must be signed in to change notification settings - Fork 26
How to inherit only few methods from v1 version #26
Comments
Hm, it looks like there isn't a way to do this yet. Ideally you'd be able to do something like: api vendor_string: "myvendor", default_version: 1 do
version 1 do
cache as: 'v1' do
resources :authorizations
end
end
version 2 do
inherit from: 'v1' do
resources :authorizations, only: [:index]
end
resources :authorizations, except: [:index]
end
end |
Yes sure you are right. This gem can ease the life of a developer if you provide this feature in your gem :-) |
To come back to this, it's about order of operations. rails reads routes from the top down. you are misunderstanding what "inherit from 'v1' means, it means add everything from v1, then add more. if you had to pick every route to inherit from, it would make the inheritance pointless. the "inheritance" is just syntactic sugar for automatically defining all routes that already exist. also think about how ridiculously complex this would get for how to try to pick and choose what routes to inherit and what not to. How fine-grained is it supposed to be? the feature you are requesting is not really possible. I actually make my newest version the source of truth in the routes file, then have older versions inherit from it so that they can override new routes with "does not exist for this version" errors. this satisfies the rails conventions of top-down routing if you want to pick and choose what to define at all, define the resource before inheriting, or don't inherit @davidcelis your example also makes no sense really. this is a routes file, not the controller, if you define all the routes except index in the inheritance, then define the index outside the inheritance, you are still ending up with the exact same available endpoints, pointing to the exact same controller methods, only through multiple definitions, and that index wont be considered until after all other routes in the list. api vendor_string: "myvendor", default_version: 1 do
version 1 do
cache as: 'v1' do
resources :authorizations
end
end
version 2 do
resources :authorizations, except: [:index]
get "authorizations", to: "error_message"
inherit from: 'v1'
end
end |
You guys both seem to be confusing the routes with the controller. To override controller actions, define those methods again in the newer version controller |
I don't know whether it is handled or not but I didn't find any documentation regarding inheriting only few methods from previous version.
eg.
Thanks.
The text was updated successfully, but these errors were encountered: