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

Having trouble assigning the value of a method to an instance variable- Task 2 of 4- Building apps with Sinatra

Not sure what I'm doing wrong with this one. Can't seem to figure out how to assign the value of the load_signature() method to my @signature instance variable.

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
  # YOUR CODE HERE
  load_signature(@index) 
  @signature = load_signature()
  @index = (params["index"])
end
views/edit.erb
<p>Please enter your name below.</p>

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

2 Answers

Oğulcan Girginc
Oğulcan Girginc
24,848 Points

The problem is in lines 13 and 14:

  load_signature(@index) 
  @signature = load_signature()

On line 14, your method needs an object as a parameter, but you forgot to write it.

If you just want the right answer, let me know! :)

Got it. Thanks!

load_signature(@index)
@signature = load_signature(@index)