In Place Editing

TechStuff Rails

Sun Mar 23 21:00:00 -0700 2008

I like the in_place_edit plugin.

I needed it to work with validations in my model, though. It doesn’t.

I also needed it to work with a select box. It doesn’t.

So after some googling I found a few extensions that accommodate each of these shortcomings….

First I found this for the validations: http://www.pluitsolutions.com/2007/03/20/custom-inplaceedit-with-validation/

This one is about a year old, and was written for Rails 1.x. Be sure you use :script => true in the calls in your view.

Then a few days ago I found this for selection: http://thetacom.info/2008/03/21/rails-in-place-editing-plugin-w-selection/#comment-7

So far I have them all working in a handful of forms. Some of them are even inside a redbox (lightbox). There is a catch, though. I was not able to get the selection edit to work with the validations. That’s OK for me, though, as there are no validations required for the data in the select.

Here’s what the controller looks like for that view:

  Employee.content_columns.each do |column|
    in_place_edit_with_validation_for :employee, column.name
  end
  # the select box extension doesn't seem to work with the custom in place editor
  in_place_edit_for :employee, "department"

So after all of that, I stumbled across this plugin that appears to do it all: http://os.flvorful.com/super_in_place_controls

Dang. I have something that works today, but it feels a little duct taped together. I’ll come back to this one.

The other thing I need to get my head around is how to put the contents of an array defined in the model into the select:

  EMPLOYEE_DEPARTMENTS = [
    # Displayed             # stored in DB
    [ "Contractor",         28 ],
    [ "Account - Internal", 29 ],
    [ "Account - External", 30 ],
    [ "Technology",         31 ]
  ]

For now to get the code running I have the values duplicated in the view. That is bad, but I was focused on other things before DRYing that up. I’ll get there….

blog comments powered by Disqus