Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Made and ran test.rb exactly per instructions, however the console doesn't return anything.

I've set up the file exactly as described in the video (within folder "pages") called it in test.rb as shown in the video too. However, when I call the file in console I get an empty space (in console). I'm using cloud9 for my test environment (loading all the necessary gems for sinatra) and up to this point all the code's worked fine.

for reference my file tree is:

wiki
-pages
--nick pettit.txt
-views
test.rb
wiki.rb

on commenting out the rescue clause; I get "no such file or directory pages/nick pettit.txt -- However, the folder is there and the file's in said folder clear as day.

help...?

1 Answer

Ok, I feel I've solved this issue. when it comes to file.read after much googling outside of treehouse of course:

Unlike the server running workspaces in treehouse , c9.io prefers one give the entire file path leading to .txt file. So in my case:

def page_content(title)
  File.read("wiki/pages/#{title}.txt")
rescue Errno::ENOENT
  return nil
end

Unlike in the video instructions:

def page_content(title)
  File.read("pages/#{title}.txt")
rescue Errno::ENOENT
  return nil
end

Maybe this'll help others working in dev environs outside workspaces provided.