sinatra helper in external file

后端 未结 5 1492
半阙折子戏
半阙折子戏 2021-02-07 06:48

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_na

5条回答
  •  无人共我
    2021-02-07 07:14

    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.

提交回复
热议问题