dimanche 11 janvier 2015

Loading two external files into my routes.rb causes issues in Rails 4 with instance_eval

I separate my routes into two files ( marketing_site.rb and subdomains.rb ) which I load in a way that Rails 4 objects :



class ActionDispatch::Routing::Mapper
def draw routes_name
instance_eval(File.read(Rails.root.join('config', 'routes', "#{routes_name}.rb")))
end
end

MyApp::Application.routes.draw do
constraints(lambda { |request| Config.main_site? request }) do
draw :marketing_site
end
constraints(lambda { |request| ! Config.main_site? request }) do
draw :subdomains
end
end


But this produces this error when trying to boot the app :



/Users/mycomputer/Sites/my_app/config/routes.rb:3:in `instance_eval': You should not use the `match` method in your router without specifying an HTTP method. (RuntimeError)
If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.
If you want to expose your action to GET, use `get` in the router:
Instead of: match "controller#action"
Do: get "controller#action"


I don't get the impression that Rails understands what I'm trying to accomplish. Anyone have an idea how I can circumvent this?


Aucun commentaire:

Enregistrer un commentaire