# Trouble adding to database (stringify\_keys)

**URL:** <https://www.ruby-forum.com/t/trouble-adding-to-database-stringify-keys/89725>\
**Category:** Rails\
**Created:** [March 29, 2006, 4:43am UTC](https://www.ruby-forum.com/t/trouble-adding-to-database-stringify-keys/89725 "2006-03-29T04:43:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [March 29, 2006, 4:43am UTC](https://www.ruby-forum.com/t/trouble-adding-to-database-stringify-keys/89725/1 "2006-03-29T04:43:16Z")

</div>

I’m brand new to rails and am trying to build a simple ajax email  
collection form. It’s just a coming soon sort of thing where the user  
can enter his email address in the field, hit submit, and the ajax form  
dumps the email into the database and says “success” unless the email is  
blank or not unique in which case it says “failure.”

The trouble is, no matter what I seem to do, when I actually go to  
create the new row in the database, I get the same error:

undefined method `stringify\_keys!’ for “removed\_email\_address@domain.invalid”:String

I’ve tried messing with .to\_s but that doesn’t help. Searching on  
google for that error message hasn’t turned up anything helpful. I’m  
really stuck and would greatly appreciate some help

Thanks,

Aaron Powell

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [March 29, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/trouble-adding-to-database-stringify-keys/89725/2 "2006-03-29T18:01:39Z")

</div>

Aaron,  
I seem to be having the same problem with a call to  
update\_attributes({})  
after upgrading to rails 1.1. I’ll let you know after I poke around and  
figure it out.

Zack

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [March 29, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/trouble-adding-to-database-stringify-keys/89725/3 "2006-03-29T18:13:09Z")

</div>

Zack C. wrote:

> Aaron,  
> I seem to be having the same problem with a call to  
> update\_attributes({})  
> after upgrading to rails 1.1. I’ll let you know after I poke around and  
> figure it out.
> 
> Zack

Thanks for the help. I was having the same trouble before upgrading so  
I don’t know that it’s directly related for me.

For the record, here’s the code I have in my “splashpage\_controller.rb”  
file:

* * *

class SplashpageController \< ApplicationController  
def addemail  
newemail = NotifyEmail.new  
newemail.attributes = @params[:notify\_email]

```
if @notify_email.save
  render(:partial => 'emailfailure')
else
  render(:partial => 'emailsuccess')
end

# @notify_email = NotifyEmail.new(params[:notify_email])
# if params[:notify_email] == "fail"
# render(:partial => 'emailfailure')
# else
# render(:partial => 'emailsuccess')
# end

```

end  
end

* * *

and the form:

* * *

\<%= form\_remote\_tag(  
:name =\> ‘email\_signup’,  
:url =\> {:action =\> ‘addemail’},  
:update =\> ‘result’,  
:complete =\> visual\_effect(:shake, ‘result’)  
) %\>

```
<label for="emailaddress">Email Address:</label>
<%= text_field_tag :notify_email %>
<%= submit_tag "Get Notified" %>

<div id="result">Enter your email.</div>

```

\<%= end\_form\_tag %\>

* * *

trying either of the database update blocks in the controller gives the  
same error.

-Aaron Powell

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [March 29, 2006, 8:30pm UTC](https://www.ruby-forum.com/t/trouble-adding-to-database-stringify-keys/89725/4 "2006-03-29T20:30:44Z")

</div>

Aaron,  
Your main problem is that you are using attributes= which expects a  
hash  
yet you are passing in a String.  
What you should do is use text\_field(:notify\_email, :email) instead of  
text\_field\_tag (see docs).

So your form should look like this:  
\<%= form\_remote\_tag(…)

```
   <label for="notify_email_emailaddress">Email Address:</label>
   <%= text_field :notify_email, :emailaddress %>
  ...

```

\<%= end\_form\_tag %\>

and your controller should look like:  
def addemail  
@notify\_email = NotifyEmail.new(params[:notify\_email])

if @notify\_email.save  
render(:partial =\> ‘emailfailure’)  
else  
render(:partial =\> ‘emailsuccess’)  
end

end

Zack

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [March 29, 2006, 8:38pm UTC](https://www.ruby-forum.com/t/trouble-adding-to-database-stringify-keys/89725/5 "2006-03-29T20:38:03Z")

</div>

Zack C. wrote:

> Aaron,  
> Your main problem is that you are using attributes= which expects a  
> hash  
> yet you are passing in a String.

Ah hah! That did it. Thank you so much.

-Aaron Powell
