Skip to content

Instantly share code, notes, and snippets.

@malachaifrazier
Created August 8, 2012 05:23
Show Gist options
  • Save malachaifrazier/3292376 to your computer and use it in GitHub Desktop.
Save malachaifrazier/3292376 to your computer and use it in GitHub Desktop.
Sinatra, Datamapper, PostgreSQL, ruby 1.9.3p194. Horrid Error "NoMethodError at /undefined method `each' for "MyNameHere":String"
<form action="/" method="post">
<p>
<label>Name</label>
<input type="text/plain" name="name" >
</p>
<p>
<input type="submit">
</p>
# This works just fine when getting name from contact form.
post "/" do
params[:name]
@u = User.new({:name => params[:name]})
@u.save
if @u.save
redirect "/success"
else
redirect "/"
end
end
# This does not. In Ruby 1.9.x strings are no longer enumerable and 'string.each' is
# undefined and returns this error even when I don't use '.each' directly.
# NoMethodError at /undefined method `each' for "MyNameHere":String
post "/" do
@u = User.new(params[:name])
@u.save
if @u.save
redirect "/success"
else
redirect "/"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment