In place editing for non-standard values

I would like to add in-place editing functionality to my application,
but I fetch & store the data from/into a weird source that requires some
transformations to be done before displaying & storing the content.

A slightly (over)simplified example could be the following.

Assume that I have a table “data” with two columns:

id name


1 XX
2 XXXX
3 XXX

show.html.erb would return the following for each object:

data/1

this is id: 1
length: 2 [edit button]

data/2

this is id: 2
length: 4 [edit button]

data/3

this is id: 3
length: 3 [edit button]

I would like to press [edit button] (or a simple link) that should
change the number into editable field that should only accept numbers.


this is id: 2
length: |4| [save button]

And when changing 4 into 6 and pressing [save button] I want to modify
the name in database to store six X characters instead of four:

id name


1 XX
2 XXXXXX
3 XXX

and return to normal show page:

data/2

this is id: 2
length: 6 [edit button]

Is there a simple way to do that with existing macros? (I’m using rails
2.1.)

Thanks a lot,
Mojca