Ruby Building Web Apps with Sinatra Finishing Touches A DELETE Request

Oleg Kufalskyi
Oleg Kufalskyi
5,849 Points

6/6 test Finally, at the end of the route block, redirect the browser to the /signatures/new path. Pls help .

Cant understand what im doing wrong((

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

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

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 ROUTE GOES HERE
delete "/signatures/:index" do
   delete_signature(params[:index],  )
end

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

1 Answer

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! You're doing great, but your delete block is missing a redirect. Inside the delete block, you should have this line:

   redirect "/signatures/new"

Hope this helps, but let me know if you're still stuck! :sparkles: