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 7953437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:09:33+00:00 2026-06-04T03:09:33+00:00

I use only one file for sinatra application ( sinatra.rb ) where I have

  • 0

I use only one file for sinatra application (sinatra.rb) where I have a route:

get '/ajax2?' do
  my_function()
end

Can I call my_function() from another ruby script (cron.rb) and passing all the params? So whatever code is in this route is executed the same way if I accessed it from a browser?

I need to call it from a cron job.

  • ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
  • sinatra (1.3.2)
  • sinatra-advanced-routes (0.5.1)
  • sinatra-reloader (0.5.0)
  • 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-04T03:09:34+00:00Added an answer on June 4, 2026 at 3:09 am

    update:

    pretty sure all you need is a module, like so, in my_module.rb:

    module MyModule
      def my_function
      end
    end
    

    then in your app.rb:

    require './my_module.rb'
    helpers MyModule
    

    you you can require and include that module in your cron.rb


    If I follow your question correctly (not sure I do), pull your code out into an extension, so your directory structure looks like this:

    myapp/
    |-lib/
      |-my_extension.rb
    |-app.rb
    

    then in my_extension.rb:

    module Sinatra
      module MyExtension
        def self.registered(app)
          app.get '/ajax2?' do
            "hallo"
          end
        end
      end
      register MyExtension
    end
    

    and in app.rb all you should need is:

    require './lib/my_extension.rb'
    

    that’s the first step, then move the contents of your extension into a gem and you can require the gem in your Gemfile in any sinatra application.

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

Sidebar

Related Questions

can someone help me with the code to use only one file. e.g. domain.com/
How could I refactor this code to use only one Dir[ ] call? Dir[
Here is my problem. If I use only one Windows Forms project and call
How to chose only one picture which can't repeat? I tried this: I use
what is the way to use only one centralised javascript file in sharepoint 2007
When I use the 'multiple' attribute I can't get it to work: <input type=file
i think both are same,but i found use of them in only one file
Untill now in C# MVC3 i only had to use one controller which used
I'm building a one-page(one file) site and want to get insight as to whether
I'm trying to use xmlrpc client from many QThreads. To make sure that only

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.