Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Michael Walker
Michael Walker
598 Points

Error msg "private method 'print' called for File:Class"

I am trying to write content to a new file using the post method. The file is created, however, it is blank.

1 Answer

Daniel Vigil
Daniel Vigil
26,473 Points

Try using the write or puts method as in the following example.

# open and write to a file with ruby
open('myfile.out', 'w') { |f|
  f.puts "Hello, world."
}
Michael Walker
Michael Walker
598 Points

Daniel, thank you very much! This worked. I was able to post my title and data from my input box, on my webpage, into a file.