Skip to content

Instantly share code, notes, and snippets.

@skive
Created July 22, 2015 20:49
Show Gist options
  • Save skive/21c4c0524b614c00af32 to your computer and use it in GitHub Desktop.
Save skive/21c4c0524b614c00af32 to your computer and use it in GitHub Desktop.
# I like how Rails has each controller in it's own file and it's automatically loaded and I'm trying to do the same for my Sinatra site.
# I have, for example, my "Users" pages, which is users/login, users/logout and so on, what I'd like to do is seperate all these, and other pages, like news, admincp, and so on into their own files.
# This is how I accomplished this with my project.
# I put all the "controllers" in a directory, I then created a file named init.rb with the following code:
Dir.glob(File.dirname(__FILE__) + '/*.rb').each do |controller|
require(controller)
end
# Then in my main app file the following code:
__DIR__ = ::File.dirname(__FILE__)
require __DIR__ + '/controllers/init'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment