This snippet is from my admin. I have a description field next to an image, and a demo of how’d that look below it.
Right now it works after a page refresh but i’d like it to work asynchronously using AJAX, so as the user types it updates the demo below the textarea.
#This is where you update the field
<tr><th>Description</th><td><%= f.text_area(:description) %></td></tr>
<tr><th>Demo</th>
<td>
<% if @org.images.present? %>
<table border="0">
<tr>
<td>
<%= featured_image_tag(@org, :type => 'organization') %>
</td>
<td style="vertical-align:top;padding-top:5px;padding-left:5px;">
<span class="font-avebook"><%= @org.description %> </span><br>
</td>
</tr>
</table>
<% else %>
You need to assoicate an image first before seeing the demo!
<% end %>
</td>
</tr>
To get the text to appear directly below at the same time as you’re writing you need to use a jQuery Keyup event to submit the data. However, submitting the data after each keyup is not the best idea. If you want to get that effect, why don’t you just do the whole thing with jQuery without actually saving the data. You can append the contents of the input to the element beside the image after each keyup. I’ve made a little demo below.
Adapted to your code: