Update_field question


#1

I’m using update_field to update a

with the contents of a
text_area as it’s updated by the user (a-la-Typo preview style).

I’m now trying to preload the

so that it shows the contents of the
field being edited even if that field doesn’t get edited. In other
words, update_field is only called if the field is updated, but I want
the same
to show the contents of the field even if the user
doesn’t edit the field (the reason being that the
is the
textilized contents of the field).

So my idea was to have another

with the field contents, and then
remove or clear that
when the update_field is called (so it isn’t
displayed twice).

so in my rhtml file I have:

this div is preloaded with field contents

<div id="pre_preview" class="post"><%= textilize(@song_words_chords) 

%>

this div is updated by update_field

<div id="preview" class="post"></div>

<%= observe_field “song_words_chords”,
:frequency => 1,
:update => “preview”,
:url => { :action => “preview” },
:with => “‘song_words_chords=’ + escape(value)” %>

then in my preview.rhtml, which is called by the preview action (which
updates the contents of @song_words_chords, I have:

<%= update_element_function("pre_preview", { :action => :empty }) %>

<%= textilize(@song_words_chords) %>

But instead of emptying the “pre_preview” div, update_element_function
just displays the following on the page:

$(‘pre_preview’).innerHTML = ‘’;

Does update_element_function only work on div’s defined in the same
rhtml file? Or am I misusing it?

I have a feeling I’m using an altogether incorrect approach for this
anyway, but being new to both Rails and JS I’m not sure what the correct
approach would be.

Any advice would be appreciated. Thanks!