NewbieQ : undefined method `stringify_keys!' Dumb Question


#1

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:ininitialize_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:innew’
#{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.


#2

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:ininitialize_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:innew’
#{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.


#3

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.


#4

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

Dave

On 12/22/05, Eric S. 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


Site: http://antidis.com/