I’m working on Rails 5.2 migration, and there is a deprecation error:
DEPRECATION WARNING: Using a dynamic :controller segment in a route is deprecated and will be removed in Rails 6.0. (called from block in <top (required)> at /home/ik/projects/foreman/config/routes.rb:17)
The error is for the following code:
get '(:controller)/help', :action => 'welcome', :as => "help"
The above support was supposed to be removed on rails 5.2, but they decided for now to wait for rails 6 instead.
The path of (:controller)
is called dynamic segment. Both (:controller)
and (:action)
are deprecated.
From action_dispatch/routing/route_set.rb
for actionpack 5.2.0 line 580-609:
def add_route(mapping, name)
raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)
if name && named_routes[name]
raise ArgumentError, "Invalid route name, already in use: '#{name}' \n" \
"You may have defined two routes with the same name using the `:as` option, or " \
"you may be overriding a route already defined by a resource with the same naming. " \
"For the latter, you can restrict the routes created with `resources` as explained here: \n" \
"http://guides.rubyonrails.org/routing.html#restricting-the-routes-created"
end
route = @set.add_route(name, mapping)
named_routes[name] = route if name
if route.segment_keys.include?(:controller)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Using a dynamic :controller segment in a route is deprecated and
will be removed in Rails 6.0.
MSG
end
if route.segment_keys.include?(:action)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Using a dynamic :action segment in a route is deprecated and
will be removed in Rails 6.0.
MSG
end
route
end
The thing is, unless I’ved missed something, there is no new way to create a dynamic segment.
I found few hacks to do it (like keeping a list of all controllers), and they ugly and hard to do with foreman due to the rails engines, and not to mention the number of controllers we have.
I have only bad ideas on how to change this routes, and I’m looking for good ideas instead.
So any ideas in the matter are more then welcome.