Forum: Ruby on Rails Simple RJS Calls Not Working

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
352e52e63e020a68da84a3bb3a141d54?d=identicon&s=25 Daniel Curran (Guest)
on 2007-04-04 23:35
(Received via mailing list)
I have a simlple view:

<% unless @recipe.tags.empty? %>
        <tbody id="tags">
            <%= render :partial=>'tags/tag', :collection=>@recipe.tags
<% end %>
<% form_remote_tag :url=>tags_path(@recipe) do%>
    <label>Name</label> <%= text_field_with_auto_complete :tag, :name %>
    <%= submit_tag "Add Tag" %>
<% end %>

Which has a pretty simple create method that renders the RJS as follows:

format.js {
          render :update do |page|
            page.insert_html :bottom, 'tags', :partial=>'tags/tag'

The problem is that no insertion happens. Under IE I get an RJS alert,
under FF I get nothing.
Firebug reports that the POST request is successful and has the has
the correct results:

try {
new Insertion.Bottom("tags", "<tr>\n    <td>Please Work</td>\n
<td><a href=\"/recipes/6/tags/28;edit\">Edit</a></td>\n    <td><a
href=\"/recipes/6/tags/28\" onclick=\"if (confirm('Are you sure?')) {
var f = document.createElement('form'); = 'none';
this.parentNode.appendChild(f); f.method = 'POST'; f.action =
this.href;var m = document.createElement('input');
m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
m.setAttribute('value', 'delete'); f.appendChild(m);f.submit();
};return false;\">Delete</a></td>\n</tr>\n");
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('new
Insertion.Bottom(\"tags\", \"<tr>\\n    <td>Please Work</td>\\n
<td><a href=\\\"/recipes/6/tags/28;edit\\\">Edit</a></td>\\n    <td><a
href=\\\"/recipes/6/tags/28\\\" onclick=\\\"if (confirm(\'Are you
sure?\')) { var f = document.createElement(\'form\');
= \'none\'; this.parentNode.appendChild(f); f.method = \'POST\';
 = this.href;var m = document.createElement(\'input\');
m.setAttribute(\'type\', \'hidden\'); m.setAttribute(\'name\',
\'_method\'); m.setAttribute(\'value\', \'delete\');
f.appendChild(m);f.submit(); };return
false;\\\">Delete</a></td>\\n</tr>\\n\");\n'); throw e

I threw the above JS into a test page and it works successfully, but
for some reason it is not working through the form. Again, in IE the
error is thrown, and in Fire Fox nothing is happenning at all. No
warnings or errors are thrown.

Anyone have any ideas on what I am doing wrong?

6925c1e7ea432d878f1832d857d6dfe8?d=identicon&s=25 Richard Luther (Guest)
on 2007-04-04 23:51
(Received via mailing list)
Are the prototype and scriptaculous libraries listed in the head of
the layout? I imagine that without them POST will still return the RJS
but the browser wont do anything with it.
 - Richard
352e52e63e020a68da84a3bb3a141d54?d=identicon&s=25 Daniel Curran (Guest)
on 2007-04-05 00:45
(Received via mailing list)
I have the following in the top of the HTML output, via <%=
javascript_include_tag :defaults %>

<script src="/javascripts/prototype.js?1171470794"
<script src="/javascripts/effects.js?1171470794"
<script src="/javascripts/dragdrop.js?1171470794"
<script src="/javascripts/controls.js?1171470794"
<script src="/javascripts/application.js?1171470794"

IE is trying to do something with it, as the exception case is being
thrown. I have not gone down the route of adding breakpoints into the
Prototype library via Firebug to figure out what has been fired and
what has not been fired. That will be my next step.

Another note is that text_field_with_auto_complete is working fine, so
the javascript libraries are working and performing remote call
successfully. It is just my form_remote_tag and the RJS that is not
doing what I would expect it to.

This topic is locked and can not be replied to.