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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:58:20+00:00 2026-05-16T07:58:20+00:00

I am writing a Rails 3 generator, but things get a bit complicated so

  • 0

I am writing a Rails 3 generator, but things get a bit complicated so I would like to extract some code to put it in a separate file.

So I create a file in the generator folder, and within my generator file, I put at the top:

require 'relative/path/to/my/code.rb'

But when I launch the generator, it tells me that it can’t find the file.

activesupport-3.0.0.rc/lib/active_support/dependencies.rb:219:in `require': no such file to load -- relative/path/to/my/code.rb (LoadError)

Does anybody know a work around ?

  • 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-16T07:58:21+00:00Added an answer on May 16, 2026 at 7:58 am

    It depends which Ruby version you are using.

    In 1.8, it should work as you do. In 1.9 you should use require_relative.

    You should also not add ‘.rb’ at the end, this is not recommended.

    The danger with a simple ‘require’ with a relative path is if this script is itself required by another, then the path will be relative to the first script called:

    rootdir
      - main.rb
      - subdir1
        - second.rb
        - subdir11
          - third.rb
    

    If main.rb is called, and then require second.rb (with 'subdir1/second'), and then you want to require third.rb with 'subdir11/third.rb', it will not work.

    You could be relative to the first script (subdir1/subdir11/third.rb), but that is not a good idea.
    You could use __FILE__ and then make it an absolute path:

    require File.expand_path(‘../subdir11/third.rb’, FILE)

    (the first .. is to get in the directory which contains the file) or

    require File.dirname(FILE) + ‘/subdir11/third.rb’

    But the most common practice is to reference it from the rootdir.

    In a gem, you can assume the rootdir will be in the $LOAD_PATH (or you can add it yourself).

    In Rails you can use require "#{RAILS_ROOT}/path" (rails2) or

    require Rails.root.join('path') (rails3)

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

Sidebar

Related Questions

I'm writing a rake task that does some DB work outside of Rails/ActiveRecord. Is
I'm writing a quick Rails app and was wondering how I can validate the
Sorry for the slightly noobish question, as I am writing my first rails app.
I'm starting work on a project using Rails, but I'm waiting for the 3rd
Writing some test scripts in IronPython, I want to verify whether a window is
Writing the code for the user authentication portion of a web site (including account
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
let's say I am writing a Ruby on Rails program and while editing a
I hate writing migrations, but it's important for the schemas to stay in sync.
I'm writing a small CMS as a Rails test project (also planning to use

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.