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 Updating Data An Edit Form

How to call the "erb" method within the route block? I have brain fog atm.

Challenge task 3 of 4!

guestbook.rb
require "sinatra"

# Loads the signature at the given line index.
def load_signature(index)
  lines = File.readlines("signatures.txt")
  # Parameter is a string; convert to integer
  index = index.to_i
  lines[index]
end

get "/:index/edit" do
  @index = params[:index]
  @signature = load_signature(@index)
end
views/edit.erb
<p>Please enter your name below.</p>

<form>
  <input type="text" name="signature" value="<%= %>">
  <input type="submit">
</form>

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,717 Points

I tend to forget the Sinatra syntax when I switch to other web frameworks. Fortunately the syntax is super simple!

I think the syntax you are looking for is this:

get "/:index/edit" do
  # YOUR CODE HERE
  @index = params['index']
  @signature = load_signature(@index)
  erb :edit
end