afeld / jeditable-rails

a gem to add in-place-editable fields to your Rails project
MIT License
34 stars 18 forks source link

Use with a not yet saved object #13

Open duffyjp opened 12 years ago

duffyjp commented 12 years ago

I'm trying to use the editable_field method with a new object. I've setup my controller/routes to handle it, and it works fine except for one gotcha. I'm using "Tagging.new" for the object passed to editable_field, and since it doesn't have an id, the "data-id" in the span and jquery line is blank. So when I list a bunch of editable_fields on the same page, only the first one is POSTed to. The new Tagging object I'm using isn't actually saved, so I thought throwing some other value into it's id would be a work around, but you can't actually do that, as it's restricted.

Could the "data-id" be something available in the options hash, akin to the :update_url? My understanding is that it doesn't actually matter what the data-id is, so long as it's unique to the object on the page.

I'll play around with it myself, but I thought I'd throw that out there to see what you think. Maybe the data-id does more than I realize.

For the sake of example, here is my call to editable_field:

editable_field Tagging.new, :tag_id, :type => 'select', :data => @tags_json, :update_url => person_taggings_path(person), :method => 'POST', :onblur => 'submit'

My controller then creates a new Tagging with the person_id and tag_id sent.