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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:15:44+00:00 2026-05-15T14:15:44+00:00

So, I wrote a simple Ruby class, and put it in my rails /lib

  • 0

So, I wrote a simple Ruby class, and put it in my rails /lib directory. This class has the following method:

def Image.make_specific_image(paths, newfilename)
  puts "making specific image"
  @new_image = File.open(newfilename, "w")
  puts @new_image.inspect
  @@blank.each(">") do |line|
    puts line + "~~~~~"
    @new_image.puts line
    if line =~ /<g/
      paths.each do |p|
        puts "adding a path"
        puts p
        @new_image.puts p
      end
    end
  end    
end

Which creates a new file, and copies a hardcoded string (@@blank) to this file, adding custom content at a certain location (after a g tag is found).

If I run this code from ruby, everything is just peachy.

HOWEVER, if I run this code from rails, the file gets CREATED, but is then empty. I’ve inspected each line of the code: nothing I’m trying to write to the file is nil, but the file is empty nonetheless.

I’m really stumped here. Is it a permissions thing? If so, why on EARTH would Rails have the permissions necessary to MAKE a file, but then not WRITE to the file it made?

Does File I/O somehow work differently in rails?

Specifically, I have a model method that calls:

Image.make_specific_image(paths, creature.id.to_s + ".svg")

which succesfully makes a file of the type “47.svg” that is empty.

  • 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-15T14:15:45+00:00Added an answer on May 15, 2026 at 2:15 pm

    Have you tried calling close on the file after you’re done writing it? (You could also use the block-based File.open syntax, which will automatically close once the block is complete). I’m guessing the problem is that the writes aren’t getting flushed to disk.

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

Sidebar

Related Questions

still fairly new to ruby, and wrote this very simple recursive function. def test(input)
A couple of weeks ago, I wrote a simple Ruby script to test a
I wrote simple class that on the start it just increase the value of
I have built a variety of little scripts using Ruby's very simple Queue class,
I'm having trouble deserializing a ruby class that I wrote to YAML. Where I
I wrote a simple EventMachine server like this one: EventMachine.run do EventMachine::WebSocket.start(:host => HOST,
I have a vote model, which has a class method called score . Basically,
I wrote a simple ruby function and I want to test if the function
i wrote simple 3 functions to scrape titles , description and keywords of simple
I wrote simple load testing tool for testing performance of Java modules. One problem

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.