routing - Rails router: Avoiding long helpers -
consider following snippet router.rb
resource :user namespace :settings resource :access_filter end 'settings' end
this generates url's want (user/settings/access_filter
), produces undesired directory structure , long url helpers.
in case, helper becomes new_user_settings_access_filter
, prefer have new_access_filter
. , rails expects accessfilterscontroller reside in module named settings
.
i way keep flat directory structure, flat url helper structure, "nested" url structure. long no parameters neccessary, don't think controllers , views needs know access filters nested under user model , retain opportunity move them options/access_filter
without breaking site.
sugggestions on how there appreciated.
if want prefix path, avoid nesting , hassle involved using separate scope
. organizationally, seems make sense well, since want decouple access filter routes user.
scope "user/settings" resource :access_filter end # if wanted change later, it's scope "options" resource :access_filter end
scope lower level function used namespace. it's far more flexible, , allows decorate paths without changing controller lookup , route names, among other things.
Comments
Post a Comment