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

Ruby Post HTML challenge

Hey there, I have been trying to solve this but keep getting bumped. Can't seem to clear the redirect portion that will redisplay. Hope a kind soul is able to help me out. Thanks!

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


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

3 Answers

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

Your goal is to redirect the user back to the form to enter another signature, after their signature is created. The way this app is set up, anytime a user's browser loads the path "/signatures/new", that form will be displayed.

So the code redirect "/#{params["signatures/new"]}" is not going to do what you want; there's no need to use a parameter here. Instead, you can simply redirect "/signatures/new".

Thanks jay !

Tobias Jackson
Tobias Jackson
9,758 Points

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

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

//this worked for me

Muhammad sharifi
Muhammad sharifi
4,455 Points

<form>

redirect "/#{params["signatures/new"]}" </form>