A project at the day job has me implementing some in pace editing. A quick search of the web found this page with a nice helper method that does all the hard work for me. Problem was, we're using RESTful routes and I was getting errors. Looking through the comments on the above linked blog post it was obvious I wasn't the only one having problems. Some more research and I think I've got it solved. Two options need to be added to the :ajax section of the options.

:ajax => {
  :ajaxOptions => "{ method: 'put' }",
  :paramName => "'my_model[my_field]'"
}

REST expects updates to be sent as a PUT, not a POST, which is what the browser wants to do by default, hence the necessity of the first option.

Next, paramName seems to be an undocumented option that I found only after digging through the Prototype source code. That changes the name of the text field in the form, so that it plays nicely with Rails apps. Obviousl,y you'll need to change 'my_model[my_field]' to the appropriate model and field names. Notice the nested double and single quotes... these are IMPORTANT!

With those two options added to the rest, it seems to work like a charm.

Comments:
Not quite working
Posted By: Matthew on 16 Aug 2007 09:11
Hi Jon,

I was just reading your post on in-place editing on RESTful routes. I've tried adding the change to my view, but I'm still getting an error.

Is the controller code for the update method different than what Coda Hale has on his blog?

Thanks,

Matthew
Yup
Posted By: Jon on 16 Aug 2007 12:37
Mathew,
That particular project has, as projects tend to do, evolved way beyond what it was when I wrote the original article, so I'm having to rely on memory, but...
Yes, as I recall the controller code was pretty basic. Make sure you've got those nested double and single quotes in the one option like I mention above. As I recall, it was giving me a lot of headaches until I figured that part out.
[add comment]