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.


Francisco Palma
Francisco Palma
1,646 Points

Bad request when trying to edit a page: Bad URI `/%3C&=%20@title%20%%3E/edit'.


So i have this problem with my code when i want to edit a page.

My code looks like this:


require "sinatra"
require "uri"

set :bind, ""

def page_content(title)
rescue Errno::ENOENT
  return nil

def save_content(title, content)
  File.open("pages/#{title}.txt", "w") do |file|

get "/" do
  erb :welcome

get "/new" do
  erb :new

get "/:title" do
  @title = params[:title]
  @content = page_content(@title)
  erb :show

get "/:title/edit" do
 @title = params[:title]
 @content = page_content(@title) 
 erb :edit

post "/create" do
  save_content(params["title"], params["content"])
  redirect URI.escape("/#{params["title"]}")

And my edit.rb looks like this (I jumped one step ahead in the course, that´s why it has some more syntax like input type. But i found out pretty quick that i have to solve my previous problem first).

<h1>Edit Page: <%= @title %></h1>

  <form method="post" action="/<%= @title %>">
<input type="hidden" name="_method" value="put">
  <label for="content">Content:</label>
    <textarea rows="10" columns="50" name="content" id="content"></textarea>
  <input type="submit">

<a href="/">Back to Index</a>

Any ideas? My code is identical to the teachers code in the video and i tried to do a hard refresh on my browser too. The edit page is one that is in the course (Nick Pettit)

I decoded the error message and got this: /<&= @title %>/edit

Is it my routing or my erb?

Thank you.