Forum: Ruby on Rails JSON problems in update method (ExtJs, Ext)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Adam W. (Guest)
on 2008-11-04 20:45
Hello rubyonrails peeps, my first post here.

I've been having a lot of trouble today getting my controller to
respond properly to an update request via json, coming from an
EditorGridPanel in ExtJS. I started off by using the ExtScaffold
plugin (which is great but limited in its examples), and hacked together
a helper for Ext's EditorGridPanel.

I've tried both the json_request plugin and the built in rails 2.1
json handling. Both end up with the same problem:

NoMethodError (undefined method `{"id":6, .... }=' for
#<ModelName:0xb5957c74>): etc...

So the JSON is not being parsed out as a nice neat params hash. I'm at
the point where I'm about to write my own parser or call the
json_request method directly to try and get this working. I've been
checking my json requests in Firebug and it seems to be ok, with the
required 'application/json' content-type:

Accept:  application/json
Content-Type:   application/json
authenticity_token:     bcc54a2ffef408f8b0829cf310cabd411311fb92
.... }

The only difference my json seems to have from the examples given in
both json_request examples and Rails
2.1 examples
) is that the format is
post: {"id":4,"model_name[field_name]":2,"model_name[field_name]":"text"
rather than post: {"id":4,field_name:2,field_name:"text" ... }
(with the Rails 2.1 version 'post' is replaced by the model name)

my controller looks like this:

  def update
                 respond_to do |format|
                     format.ext_json { render :json =>
this.to_ext_json(:success => true) }
                       logger.debug("update failed!")
                     format.ext_json { render :json =>
this.to_ext_json(:success => false) }
I've tried everything I can think of ... it seems like I'm missing
something to trigger the json parsing, but I just don't know what at
the moment.

Any help or ideas much appreciated!!

This topic is locked and can not be replied to.