Forum: Ruby on Rails trouble adding to database (stringify_keys)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aaron P. (Guest)
on 2006-03-29 06:43
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
Zack C. (Guest)
on 2006-03-29 20:01
(Received via mailing list)
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
Aaron P. (Guest)
on 2006-03-29 20:13
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
Zack C. (Guest)
on 2006-03-29 22:30
(Received via mailing list)
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
Aaron P. (Guest)
on 2006-03-29 22:38
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
This topic is locked and can not be replied to.