开发者

Where to put Padrino controller files in standalone Sinatra application?

I'm attempting to u开发者_如何学Cse Padrino's routing as a standalone addition to a basic Sinatra application.

http://www.padrinorb.com/guides/standalone-usage-in-sinatra

The main reason I need/want the additional Padrino functionality is the ability to separate my routes into multiple controller files.

Is this something I can do without using the whole Padrino package? If so, where do I place the separate controller files? I've tried /controllers/main.rb and /app/controllers/main.rb, where my core Sinatra app is at /app.rb.


You don't quite need to use the padrino routing to achieve the idea of controllers in Sinatra. In your main .rb file for your Sinatra app you can do:

Dir.glob("controllers/*.rb").each { |r| require_relative r }

Place your "controllers" into a controllers directory and the above will require_relative all of them for you. The code all gets lumped into the main ruby file eventually but you gain the ability to logically separate the code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜