I'm in the process of upgrading a rails 3 app to rails 4.0.1.
In my rails 3 app I have the following code in the my application.rb
to use multiple route files.
config.paths["config/routes"] += Dir[Rails.root.join('config', 'routes', '*.rb').to_s]
but that throws an exception when I try to use the same thing in rails 4.
Any tips?
In one of my larger applications I use the following segment of code inside of my config/routes.rb file.
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
YourApplication::Application.routes.draw do
# Loads config/routes/common.rb
draw :common
# Loads config/routes/another.rb
draw :another
end
Rails 4 initially had support for draw :routeName
but it was removed as it did not show any improvements. (I dont know ^.^) You can check out the git commit doing so here: https://github.com/rails/rails/commit/5e7d6bba79393de0279917f93b82f3b7b176f4b5
Check out this SO answer: rails 4: split routes.rb into multiple smaller files
Looks like this ability was deprecated in Rails 4.
I don't know how big your application is. But you should look into routing concern in rails 4, if you need some proper refactoring with Rails route.
Mo' files, mo' problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With