Ruby Building Web Apps with Sinatra Adding New Data Submitting the Form Via POST Request

Andrew Ackerman
Andrew Ackerman
8,347 Points

Struggling with task 3.

I'm not entirely sure how to ask this, but I'm very confused as to what I'm doing wrong, am I over thinking this?

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"

# 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["text"], params["signature"])
  redirect URI.escape"/#{params["text"]}"
end
Andrew Ackerman
Andrew Ackerman
8,347 Points

The task is "Within the post "/signatures/create" route block, call the save_signature method. save_signature takes a signature string as an argument, so pass it the value of the signature form field."

I'd really appreciate any help! Thanks!

2 Answers

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

save_signature takes one argument, but you're passing two. Reduce it to one (and make sure it's the correct one, because only one of the two parameters you're accessing is valid), and Task 3 should pass.

Andrew Ackerman
Andrew Ackerman
8,347 Points

Thank you so much for that!