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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:51:16+00:00 2026-06-08T00:51:16+00:00

Here’s a sample of the code, which I’m trying to load from rails c

  • 0

Here’s a sample of the code, which I’m trying to load from rails c (inside the lib folder–the file data2.json is also inside of the lib directory)

$LOAD_PATH.unshift(File.expand_path(".", File.dirname(__FILE__)))
$LOAD_PATH.unshift(File.expand_path("./lib", File.dirname(__FILE__)))

require 'company_gem_class'

class LoadJson

  def go
   File.open(Rails.root, 'lib', 'file.json') do |f|
      f.each_line do |line|
        this_line = JSON.parse(line)
        hash_parser = CompanyGemClass.new(line)
        c = Company.new
        c.followers = hash_parser.followers
        c.company_name = hash_parser.company_name
        c.date_joined = hash_parser.date_joined
        ...
        c.save
      end
    end
 ...
 end

The plan was/is to load all this raw data through a single (Company) class directly from the rails console. I’ve been getting lots of “json file does not exist” (Ennooent::path/to/file.json does not exist).

I’ve tried putting it in the lib/assets folder and lib folders, but no success yet. How might I go about this task of mass-uploading these json–>ruby objects to the db?

^^I’ve already bundle-installed the json gem.
^^The json files are one hash per line, so that’s why I did it like this

  • 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-08T00:51:17+00:00Added an answer on June 8, 2026 at 12:51 am
    1. I’m sure you know (however it was not completely obvious from your question) that File.open does not use LOAD_PATH for anything. So no matter what you put in LOAD_PATH, it will not affect how File.open works. LOAD_PATH only modifies how require searches for files.

    2. In Rails all your file operations should use Rails.root as the base path. You cannot rely on your current working directory to be something specific when working with Rails.

      So any LOAD_PATH modifications should be done with something like this:

      $LOAD_PATH.unshift(File.join(Rails.root, 'my', 'uber', 'lib'))
      
    3. Because of (1) and (2) – If you’re going to open any file with File.open the most reliable way to do it is using Rails.root:

      File.open(File.join(Rails.root, 'path', 'to', 'file.json'))
      

      Or in your case:

      File.open(File.join(Rails.root, 'lib', 'assets', 'file.json'))
      
    4. In Rails lib is already in your LOAD_PATH by default. So you do not need to add it separately.

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

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here is an example: I write html code inside of textarea, then I swap
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is my code sample, let me know if it can be further improved?
Here a simple question : What do you think of code which use try
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here is my code, which takes two version identifiers in the form 1, 5,
Here is the code from my project where I am using a datepicker. The
Here I am trying to retrieve the response from the server and display it,

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.