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

  • SEARCH
  • Home
  • 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 7536019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:27:36+00:00 2026-05-30T06:27:36+00:00

I have some additional scripts that I’ve written outside of my Rails 3.1.x app,

  • 0

I have some additional scripts that I’ve written outside of my Rails 3.1.x app, however the time has come to pull data from the database of the Rails app directly rather than utilizing some exports of the data.

To this end, I’d like to integrate the scripts into my rails app. Hitherto I’ve run rake tasks based on methods in the models such as having this in my lib/taks/app.rake:

desc "Does something."
task :do_some_things => :environment do
  ModelName.some_method
  ModelName.another_method
end

If I were to place my scripts essentially into lib, would I be able to call these from a rake task? Or would I need a calling method in the model that would require lib/my_script.rb?

I have attempted to write a task like this:

task :run_me => :environment do
  `bundle exec lib/script.rb`
end

Then when this executes and I have a require within that script.rb (require 'lib/another_script.rb') I end up getting “cannot load such file” errors.

I’m obviously approaching this the wrong way at present.

It seems as though I should simply have a method invocation in the rake task that would then call the supporting scripts under /lib or elsewhere (wherever would be most appropriate).

  • 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-05-30T06:27:38+00:00Added an answer on May 30, 2026 at 6:27 am

    my preferred way of handling this sort of thing is as follows:

    • wrap each script in its entirety in a module with one action method
    • place the file which contains the method-wrapped script within lib/ (you can put multiple method-scripts in one file, or keep them one-per-file
    • require everything within lib in your Rakefile
    • within the rake task, include the module and call the method

    so, in very simple terms:

    # lib/foo.rb
    module Foo
      def bar
        puts "called me"
      end
    end
    

    and:

    # Rakefile
    require File.expand_path('../config/application', __FILE__)
    Dir[
      File.expand_path(Rails.root.join 'lib', '**', '*.rb')
    ].each {|f| require f}
    
    desc "does bar from lib"
    task :do_bar do
      include Foo
      bar
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flash player that loads in some additional features from flash files
I have a Python library that, in addition to regular Python modules, has some
I think we have a problem in our FTP scripts that pull files from
I have a FrameLayout view which contains one (MapView-like) control and some additional buttons
We have subclassed the Silverlight Application class to add some additional functionality and then
I have some arbitrary pixel data that I want to save as a PNG.
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
We have a product that we need to create an installer for. It has
I have a vb script that processes text files on a server, however, very
I have a git submodule of git://github.com/rails/rails in vendor/rails of my Rails 3 app.

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.