Ruby Building Web Apps with Sinatra Finishing Touches A DELETE Request

Brendan Connolly
Brendan Connolly
5,164 Points

I don't see what is wrong here

The delete route looks to be setup correctly, I can't see what I'm missing.

Help!

views/show.erb
<p><%= @signature %></p>

<form method="post" action="/signatures/<%= @index %>">
  <input type="submit" value="Delete This Signature"/>
  <input type="hidden" name="_method" value="delete"/>
</form>
guestbook.rb
require "sinatra"

def load_signature(index)
  # Code omitted for brevity
end

def save_signature(signature)
  # Code omitted for brevity
end

def update_signature(index, signature)
  # Code omitted for brevity
end

# Deletes the line at the given index and re-saves the file.
def delete_signature(index)
  lines = File.readlines("signatures.txt")
  index = index.to_i
  lines.delete_at(index)
  File.open("signatures.txt", "w") do |file|
    file.puts lines
 end
end

get "/signatures/new" do
  # Code omitted for brevity
end

get "/signatures/:index" do
  @index = params[:index]
  @signature = load_signature(@index)
  erb 'show'.to_sym
end

delete "/signatures/:index" do
  @index = params[:index]
  @signature = delete_signature(@index)
  redirect "/signatures/new"
end
Brendan Connolly
Brendan Connolly
5,164 Points

It is resulting in Bummer: The DELETE route path needs to start with "/signatures/".

1 Answer

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

There was an error with this challenge that we just fixed. Try again now. Your code should pass as-is. Sorry for the trouble!