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


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.