sinatra helper in external file

Viewed 9968

I have lot of helpers in my main Sinatra project_name.rb and I want to remove them to the external file, what is the best practice to do that ?

from ./preject_name.rb

   helpers do
     ...#bunch of helpers
   end

to for exapmple ./helpers/something.rb

thank you

5 Answers

I just added require_relative './lib/sinatra/helpers' to my config.ru and that's all.

So it looks like this:

require_relative './config/environment'
require_relative './lib/sinatra/helpers'
use ProjectsController
run ApplicationController

and my ./lib/sinatra/helpers.rb file is not even a module and I don't use any requires or includes in it. I can just define methods straight in this file and use them all over the app.

The answer of @kgpdeveloper didn't work for me.

Related