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 trialNoor Muhammad Iskandar
6,869 PointsRuby 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!
<p>Please enter your name below.</p>
<form method="post" action="/signatures/create">
<input type="text" name="signature">
<input type="submit">
</form>
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
Treehouse TeacherYour 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"
.
Marshall Chikari
18,109 Pointspost "/signatures/create" do save_signature (params["signature"]) redirect "/signatures/new" end
//this worked for me
Muhammad sharifi
4,455 Points<form>
redirect "/#{params["signatures/new"]}" </form>
Noor Muhammad Iskandar
6,869 PointsNoor Muhammad Iskandar
6,869 PointsThanks jay !
Tobias Jackson
9,758 PointsTobias Jackson
9,758 Pointspost "/signatures/create" do save_signature (params["signature"] redirect "/signatures/new" end ?