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

page_content(params[:title]) wont load the content of the .txt file inside pages folder.

I'm pretty sure this is happening because of an earlier issue I've had that is unresolved. That question's at: https://teamtreehouse.com/community/made-and-ran-testrb-exactly-per-instructions-however-the-console-doesnt-return-anything

Basically, as it stands right now, the page is displaying blank; nothing.

Please help.

The code as I've added:

get "/:title" do
  page_content(params[:title])
end

Hi there,

Which course is this? Can you link to the video you're at please?

Steve.

Hi,

The course is building web apps in sinatara and the videos are: Issue started in this video: https://teamtreehouse.com/library/loading-text-files and is continuing here: https://teamtreehouse.com/library/url-parameters

Thanks

OK - I've not done those so let me have a quick look at them and I'll see if I can help.

You're using c9.io - is that using Rails 5 and the course may be an earlier version?

Steve.

I appreciate it greatly as I feel this sinatra section's going to go pear shaped unless I resolve this text passing issue!

Yes, c9.io -- however I've switched the environment to sinatra (or at least installed sinatra) and as far as rails, its up to the latest version of rails at c9.io. Does that matter, will that matter?

It does with some courses as Rails 5 was a big revision. However, I just checked the workspace, and that's running Rails 5 so this isn't the issue. I shall carry on with the course and get back to you once I have caught up!

Cheers Steve, you rock!

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.