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 Building Web Apps with Sinatra Adding New Data A Route for POST Requests

Hadi Farhat
PLUS
Hadi Farhat
Courses Plus Student 7,102 Points

my form handles white spaces normally

I submitted a form with white spaces both in the title and content. There was no error messages and I did not use the URI.escape method. Maybe I use a new version of sinatra that handles this problem automatically ?

4 Answers

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

Are you passing a path with spaces in it to redirect? That's when errors are likely to occur.

Thomas Lee
Thomas Lee
6,002 Points

I learned a lot from this course. Thanks, Jay! Thankfully, my browser also handles spaces as other users mention in this forum.

However, I noticed that when saving a new page with a title that includes a "?", a new .txt file will be created, as will the page, but it will not correctly request the resource. I know question marks are used in urls to designate the beginning of a query. Any way to escape question marks to preserve the title?

Jay McGavren
Jay McGavren
Treehouse Teacher

You might do a web search for the Ruby URI::Escape module; that should help.

Also note that question marks are often a reserved character in the file names for many operating systems. Storing part of our data as a file name is a nice, simple example, but this is one of its inherent weaknesses. You might want to do a web search for Ruby's Pstore or YAML::Store libraries as a way to store data without character set limitations.

Lloyd Stevens
Lloyd Stevens
10,934 Points

Mine also accepts spaces. When submitting the data it removes the spaces accordingly with %20 This works if there are also a number of words

I imagine this is an update in the sinatra that has fixed the issue with redirect and whitespace?

Zack Guo
Zack Guo
12,135 Points

Me too! My form also handles white spaces normally without URI.escape.

the same here, my form handles white spaces normally