Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:20:44+00:00 2026-06-18T09:20:44+00:00

I’m using Rufus scheduler in a Sinatra app. Can I access helper methods from

  • 0

I’m using Rufus scheduler in a Sinatra app.
Can I access helper methods from within “scheduler do” block? I didn’t manage to do it (I get an “undefined method `check’ for main:Object” error) so now I have to define the method inside helpers block (to use it in “post ‘/’ do” block also) and then copy the method’s body to scheduler block. It does not make sense:( Is there a way to avoid repetition? Can I define a method somewhere else and call it in scheduler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:20:46+00:00Added an answer on June 18, 2026 at 9:20 am

    It depends where your scheduler is being used. A block will have access to the context local to it, so if you’re using it somewhere you have access to a helper, then it should also have access to the helper.

    Taken in part from the docs

    class MyApp < Sinatra::Base
      # Hey, I'm in the application scope!
    
      helpers do
        def my_helper
        end
      end
    
      configure do
        scheduler.every('20s') do
          # my_helper is ***not*** accessible here
        end
      end
    
      get '/define_route/:name' do
        # Request scope for '/define_route/:name'
        scheduler.every('20s') do
          my_helper
          # my_helper is accessible here
        end
      end
    end
    

    Having said that, you wouldn’t have access to the scheduler like that, so:

    configure do
      set :scheduler, { Rufus::Scheduler.start_new }
    end
    

    and then you can do

      get '/define_route/:name' do
        # Request scope for '/define_route/:name'
        settings.scheduler.every('20s') do
          my_helper
          # my_helper is accessible here
        end
      end
    

    or you could put it in a module’s class instance variable:

    module MyScheduler
      def self.scheduler
        @scheduler ||= Rufus::Scheduler.start_new
      end
    end
    

    then you can access the scheduler everywhere via:

    MyScheduler.scheduler
    

    but the my_helper would still only be accessible in the request scope. If you wanted to access a method as a helper and outside the request scope, then extract it as jmettraux implied to:

    module MyHelpers
      def self.my_helper
        # do something
      end
    end
    

    in Sinatra:

    helpers
      def my_helper
        MyHelpers.my_helper
      end
    end
    

    then can do:

    configure do
      scheduler = Rufus::Scheduler.start_new
      set :scheduler, scheduler
      scheduler.every('20s') do
        MyHelpers.my_helper
        # my_helper is not accessible here
        # but the MyHelpers.my_helper is, because it's accessible everywhere
      end
    end
    
    # and/or
    
    get "another-route" do
      setting.scheduler.every('20s') do
        my_helper
        # my_helper is accessible here
      end
    end
    

    All very convoluted! You can mix and match and find what works for your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload
I am using jsonparser to parse data and images obtained from json response. When
I am using JSon response to parse title,date content and thumbnail images and place
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.