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 "test@test.com":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 -- Posted via http://www.ruby-forum.com/.
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 On 3/28/06, Aaron Powell <aaronpowell@gmail.com> wrote:> > 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 "test@test.com":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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060329/f6c39a6f/attachment.html
Aaron Powell
2006-Mar-29 16:13 UTC
[Rails] Re: trouble adding to database (stringify_keys)
Zack Chandler 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. > > ZackThanks 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 -- Posted via http://www.ruby-forum.com/.
Zack Chandler
2006-Mar-29 18:33 UTC
[Rails] Re: trouble adding to database (stringify_keys)
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 On 3/29/06, Aaron Powell <aaronpowell@gmail.com> wrote:> > Zack Chandler 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060329/f1eaa747/attachment-0001.html
Aaron Powell
2006-Mar-29 18:58 UTC
[Rails] Re: Re: trouble adding to database (stringify_keys)
Zack Chandler 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 -- Posted via http://www.ruby-forum.com/.