Scorched
Scorched copied to clipboard
`<class:App>': uninitialized constant App::ControllerA (NameError)
require 'scorched'
class App < Scorched::Controller
get '/' do
'root'
end
self << {pattern: '/a', priority: 10, target: ControllerA}
end
class ControllerA < Scorched::Controller
get '/' do
"sub a at App"
end
self << {pattern: '/b', priority: 10, target: ControllerB}
end
class ControllerB < Scorched::Controller
get '/' do
"sub b at a"
end
end
Is Scorched must be strict order by [ControllerB ,ControllerA, App] ?
Remember you're writing Ruby code here. You can't refer to a constant (e.g. class name) before it's defined. If your example, you're referencing ControllerA and ControllerB before they've been defined.
If defining your controllers as you are, you're best to require
them all in advanced before mapping them in your main contoller. But like a lot of these things, there's always more than one way to do.
@Wardrop Is there other way to require controllers like "best practice "?