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 Finishing Touches A DELETE Request

Kyle Shamblin
Kyle Shamblin
9,945 Points

Help adding a hidden form to ERB file.

I set input type to "hidden" name to "_method" and value to "delete," am I missing something?

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 ROUTE GOES HERE

1 Answer

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

Looks like your opening <form tag is missing the closing >. I added that and was immediately able to pass Task 3 with no other changes to your code.

Kyle Shamblin
Kyle Shamblin
9,945 Points

Thanks for your help again!