Created
August 8, 2012 05:23
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="/" method="post"> | |
<p> | |
<label>Name</label> | |
<input type="text/plain" name="name" > | |
</p> | |
<p> | |
<input type="submit"> | |
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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