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:

e.g.
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
post:
{"id":4,"business_requirement[project_id]":2,"business_requirement[description]":"..",
.... }

The only difference my json seems to have from the examples given in
both json_request examples and Rails
2.1 examples
(http://www.digitalhobbit.com/archives/2008/05/25/rails-21-and-incoming-json-requests
) 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|
                   if
find_business_requirement.update_attributes(params[:post])
                     format.ext_json { render :json =>
this.to_ext_json(:success => true) }
                   else
                       logger.debug("update failed!")
                     format.ext_json { render :json =>
this.to_ext_json(:success => false) }
                   end
                 end
 end
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!!

Thanks
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to