How can I split up my codebase in Ramaze into different controller classes, and what is the most "ruby-like" way of doing so?
I have a basic project in Ramaze that I want to split into multiple files. Right now, I am using one controller class for everything and adding on to it with open classes. Ideally, each distinct part of the controller would be in its own class, but I don't know how to do that in Ramaze.
I want be able to add more functionality, and more separate controller classes, without adding on too much boilerplate code. Here's what I'm doing right now:
init.rb
require './othercontroller.rb'
class MyController < Ramaze::Controller
map '/'
engine :Erubis
def index
@message = "hi"
end
end
Ramaze.start :port => 8000
othercontroller.rb
class MyController < Ramaze::Controller
def hello
@message = "hello"
end
end
Any suggestions on how to split up this logic would be very appreciated.
The usual way to do it is to require your controllers in
init.rb, and define each class in it own file, and require it in init like so :controller/init.rb :
controller/my_controller.rb :
controller/my_other_controller.rb :
You can create a base class you inherit from so you don't have to repeat
engine :Erubisline (and probably others) in each class.If you want to serve
MyControllerat the '/' URI, you can map it to '/' :You can peek at the blog example for an example: https://github.com/Ramaze/ramaze/tree/master/examples/app/blog