# NewbieQ : undefined method \`stringify\_keys!' Dumb Question

**URL:** <https://www.ruby-forum.com/t/newbieq-undefined-method-stringify-keys-dumb-question/50936>\
**Category:** Rails\
**Created:** [December 22, 2005, 11:45pm UTC](https://www.ruby-forum.com/t/newbieq-undefined-method-stringify-keys-dumb-question/50936 "2005-12-22T23:45:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [December 22, 2005, 11:45pm UTC](https://www.ruby-forum.com/t/newbieq-undefined-method-stringify-keys-dumb-question/50936/1 "2005-12-22T23:45:40Z")

</div>

Hi,  
I’m running round in circles again! I’m trying to save a note that has a  
HABTM relationship with a job. The note is new - the job exists.  
In my partial for notes I have ;

\<%= start\_form\_tag :action =\> ‘new\_note’, :id =\> @job %\>

```
  <%= text_area_tag "note", nil, :size => "65x10" %>

  <%=submit_tag 'Add Note', :note => @job.note %>

```

\<%= end\_form\_tag %\>  
Which exists on a page containing another partial with job data.

In the controller there is ;

def dashboard\_job\_update  
@job = Job.find(params[:id])  
@note = Note.new(params[:note]) \<—this is line 99  
@job.notes \<\< @note  
if @job.update\_attributes(params[:job])…

The submitted params are;

Request

Parameters: {“commit”=\>“Add Note”, “id”=\>“1”,  
“job”=\>{“job\_state\_id”=\>“2”, “current\_action\_id”=\>“7”,  
“job\_phase\_id”=\>“2”, “job\_wait\_state\_id”=\>“4”},  
“note”=\>“xzczcxvzxcvzxc”}

The error message is;  
undefined method `stringify\_keys!’ for “xzczcxvzxcvzxc”:String

And the trace is ;  
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/base.rb:1333:in  
`attributes=' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1188:in`initialize\_without\_callbacks’  
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/callbacks.rb:236:in  
`initialize' #{RAILS_ROOT}/app/controllers/job_controller.rb:99:in`new’  
#{RAILS\_ROOT}/app/controllers/job\_controller.rb:99:in  
`dashboard\_job\_update’

See above for line 99

Can’t find much to explain this error - can anyone help?

Kind Regards,  
Eric.

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [December 23, 2005, 2:24am UTC](https://www.ruby-forum.com/t/newbieq-undefined-method-stringify-keys-dumb-question/50936/2 "2005-12-23T02:24:09Z")

</div>

I’m a little confused by how you’re approaching the addition of the  
note.

First of all, in your partial, you have:

\<%= start\_form\_tag :action =\> ‘new\_note’, :id =\> @job %\>

But the action you’re showing us in the controller is  
“dashboard\_job\_update” not “new\_note”. Your action in your  
start\_form\_tag directly correlates to what method is executed on form  
submission.

Also, and this is the cause of your stringify\_keys! error, :note is not  
a valid option for the submit tag. Its submit\_tag(value, options).  
value is whatever you want the Submit button to say and options are  
html-type options, such as :class or :id.

Here’s what I would do instead. In whatever controller that corresponds  
to the view you’ve given us below define @job (@job =  
Job.find(params[:id])) and define a new note object (@note = Note.new).  
Then use the following for your view:

\<%= start\_form\_tag :action =\> ‘dashboard\_job\_update’ %\>  
\<%= text\_area\_tag “note”, nil, :size =\> “65x10” %\>  
\<%= hidden\_field\_tag “job\_ids[]”, job.id %\>  
\<%= submit\_tag “Add Note” %\>  
\<%= end\_form\_tag %\>

Then I’d change your controller as follows:

def dashboard\_job\_update  
@note = Note.new(params[:note])  
@note.jobs = Job.find(@params[:job\_ids]) if @params[:job\_ids]  
if @note.save …

You might want to change your method name too because you’re not really  
updating a job, you’re creating a note. Also, are you sure it is a  
HABTM relationship you want? If you’re only adding each note to one  
job, then note really only needs a belongs\_to relationship with job  
(which would require different code than above of course).

Eric S. wrote:

> Hi,  
> I’m running round in circles again! I’m trying to save a note that has a  
> HABTM relationship with a job. The note is new - the job exists.  
> In my partial for notes I have ;
> 
> \<%= start\_form\_tag :action =\> ‘new\_note’, :id =\> @job %\>
> 
> ```
> <%= text_area_tag "note", nil, :size => "65x10" %>
> 
> <%=submit_tag 'Add Note', :note => @job.note %>
> 
> ```
> 
> \<%= end\_form\_tag %\>  
> Which exists on a page containing another partial with job data.
> 
> In the controller there is ;
> 
> def dashboard\_job\_update  
> @job = Job.find(params[:id])  
> @note = Note.new(params[:note]) \<—this is line 99  
> @job.notes \<\< @note  
> if @job.update\_attributes(params[:job])…
> 
> The submitted params are;
> 
> Request
> 
> Parameters: {“commit”=\>“Add Note”, “id”=\>“1”,  
> “job”=\>{“job\_state\_id”=\>“2”, “current\_action\_id”=\>“7”,  
> “job\_phase\_id”=\>“2”, “job\_wait\_state\_id”=\>“4”},  
> “note”=\>“xzczcxvzxcvzxc”}
> 
> The error message is;  
> undefined method `stringify\_keys!’ for “xzczcxvzxcvzxc”:String
> 
> And the trace is ;  
> d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/base.rb:1333:in  
> `attributes=' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1188:in`initialize\_without\_callbacks’  
> d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/callbacks.rb:236:in  
> `initialize' #{RAILS_ROOT}/app/controllers/job_controller.rb:99:in`new’  
> #{RAILS\_ROOT}/app/controllers/job\_controller.rb:99:in  
> `dashboard\_job\_update’
> 
> See above for line 99
> 
> Can’t find much to explain this error - can anyone help?
> 
> Kind Regards,  
> Eric.

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [December 24, 2005, 12:46am UTC](https://www.ruby-forum.com/t/newbieq-undefined-method-stringify-keys-dumb-question/50936/3 "2005-12-24T00:46:34Z")

</div>

Thanks David, Marc, Ed for the responses. All have been really helpful.  
My problem is turning out to be fairly fundamental insofar as I’m trying  
to run a set of partials, each with it’s own form which, I’m beginning  
to realise, is probably not a great idea. Ultimately what I’m trying to  
acheive is my main job data - customer, address, job status, etc… on a  
main page with stuff like contacts, notes, etc… on their own forms in a  
tabbed section of the main page.  
Eric.

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [December 23, 2005, 8:57pm UTC](https://www.ruby-forum.com/t/newbieq-undefined-method-stringify-keys-dumb-question/50936/4 "2005-12-23T20:57:46Z")

</div>

If I remember correctly, if you use Note.new with params[:note], then  
:note should be a hash containing the paramaters for Note. What Rails  
is trying to do is read the hash in :note, but it’s not a hash, it’s a  
string.

Assuming you’re trying to set Note.value, try this instead:

@note = Note.new(:value =\> params[:note])

changing value to whatever attribute “xzczcxvzxcvzxc” was bound for.

Have a look at the documentation for ActiveRecord:  
[http://api.rubyonrails.com/classes/ActiveRecord/Base.html](http://api.rubyonrails.com/classes/ActiveRecord/Base.html)

Dave

On 12/22/05, Eric S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> <%=submit_tag 'Add Note', :note => @job.note %>
> if @job.update_attributes(params[:job]).......
> 
> ```
> 
> undefined method `stringify\_keys!’ for “xzczcxvzxcvzxc”:String
> 
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Site: [http://antidis.com/](http://antidis.com/)
