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

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.