On Sunday, March 19, 2006, at 4:55 PM, Jeremy H. wrote:
On 18 Mar 2006 00:24:38 -0000, Lori O.
[email protected] wrote:
My environment is:
Rails 1.0 + RJS Plugin
Updated Javascripts to Scriptaculous 1.5.3 (for evalScripts support)
Monkeypatched in_place_editor to support evalScripts
I’m curious, because I’m having trouble getting the eval to happen
automagically on either Safari or Firefox when using the exact same
type of rjs template that you are using (I have to do an :complete =>
“eval…” in my tag) - why you mention Scriptaculous and the
monkey_patch eval support? Were you already using Scriptaculous for
other purposes and just needed to merge this functionality in?
Ok. I am using in_place_edit_field to allow the user to change a field.
The field is also displayed as part of a list on another part of the
page, so I have the “need to update 2 divs” problem that RJS solves.
But if you use Rails 1.0 + RJS plugin like me, you don’t get the benefit
of all the Edge Rails stuff. One of those benefits is that Edge Rails
is using the Scriptaculous 1.5.3 release. So I specifically had to
download and add those updated javascript files to my Rails 1.0 app,
because I needed this new feature from 1.5.3:
“Enable in place editor to use RJS (implements a new evalScripts option
for the in place editor), #3490 [thx Richard L.]”
I still couldn’t get the in_place_editor to do anything with
evalScripts, so I actually read the patch description:
http://dev.rubyonrails.org/ticket/3490
And I discovered:
“Note that the in_place_editor javascript helper in rails would also
need updating for this to be used with it.”
So I checked, and afaics, this fix isn’t even in Edge Rails yet. So
then I did my 1-liner monkey-patching on in_place_editor, (starting from
the Rails 1.0 version), to add evalScripts support:
js_options[‘evalScripts’] = options[:eval_scripts] if
options[:eval_scripts]
And then use that in my in_place_edit_field:
<%= in_place_editor_field :product, :name, {}, {:eval_scripts => true }
%>
After all that, I finally got my rjs templates updating my
in_place_edit_fields. Painful, and it took me the better part of 2 days
of banging my head against brick walls, but at least it works now. And
I understand plugins and monkey-patching better too. It was whatcha
call a “learning experience”.
I think the RJS plugin should be updated to include all this, to save
others time I wasted. I’ll have to try to find time to contact the
keeper of RJS plugin.
–
Lori O.
http://blog.dragonsharp.com