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

Amir Tamim
Amir Tamim
8,597 Points

Redirecting browser...

Could someone point out the flaw in my code please?

Finally, at the end of the post "/signatures/create" route, redirect the browser to the /signatures/new path (which will re-display the signature form).

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"

def save_signature(signature)
  File.open("signatures.txt", "a") do |file|
    file.puts signature
  end
end

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

post "/signature/create" do
  save_signature(params["signatures"])
  redirect URI.escape("#{params["/signatures/new"]}")
end 

You should take off params on your last row

  redirect URI.escape("#{"/signatures/new"}"

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

"/signatures/new" should be just a string - it's not a variable, so you don't need the interpolation block ( #{} ) and it's not contained in the params hash, so the only thing passed to the URI.escape() should be that string, nothing more.