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 Submitting the Form Via POST Request

Finally, at the end of the post "/signatures/create" route, redirect the browser to the /signatures/new path (which will

what wrong?

views/new.erb
<p>Please enter your name below.</p>

<form method="post" action="/signatures/create">
  <input type="text" name="signature">
  <input type="submit">
</form>
guestbook.rb
require "sinatra"
require "uri"

# Appends the signature to the file as a new line.
def save_signature(signature)
  File.open("signatures.txt", "a") do |file|
    file.puts signature
  end
end

get "/signatures/new" do
  erb :new
end

post "/signatures/create" do
  save_signature(params[:signature])
  redirect URI.escape("#{"/signatures/new"}"
end
# ADD CODE TO RECEIVE FORM SUBMISSIONS HERE

1 Answer

You are asked to pass a string to the redirect method. The following code should do the trick:

post("/signatures/create") do
  save_signature(params["signature"])
  redirect("/signatures/new")
end