Note that there are some explanatory texts on larger screens.

plurals
  1. POrails ajax render outputs a screen full of javascript
    primarykey
    data
    text
    <p>I'm trying to get some basic ajax working on rails. I have a comon main page, with a banner, sidebar and main area. In the sidebar I have added a dropdown menu and button (clunky I know, but you have to start somehere) to change an attribute of the user's view of the site (the selected network). The idea is that when the network is changed, the AJAX functionality should change the list of sites reflecting the fact that the network has changed. </p> <p>The problem is that when the AJAX code runs, I get the javascript appearing in my browser window, rather than updating the appropriate element</p> <pre><code>try {Element.update("site_list_body", "&lt;-- the correct html appears here --&gt;");} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.update(\"site_list_body\", \"&lt;--same html code here too--&gt;");'); throw e } </code></pre> <p>I've had a look round stackoverflow and google, and despite trying various suggestions, none of them seem to work at the moment. Any help would be appreciated :-)</p> <p>Thanks</p> <p>Steve</p> <p>So (with simplifications) - my main page looks like this</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html;charset=UTF-8" /&gt; &lt;title&gt;Networks: &lt;%= controller.action_name %&gt;&lt;/title&gt; &lt;%= stylesheet_link_tag 'frontier', 'menus' %&gt; &lt;%= javascript_include_tag :defaults %&gt; &lt;/head&gt; &lt;body id="frontier-network"&gt; &lt;div id="banner" &lt;--banner and menu stuff --&gt; &lt;/div&gt; &lt;div id="columns"&gt; &lt;div id="side"&gt; &lt;-- some other stuff --&gt; &lt;div id="site_list_body"&gt; &lt;%= render :partial =&gt; "shared/network_site_list", :locals =&gt; {:site_list =&gt; @site_list} %&gt; &lt;/div&gt; &lt;div&gt; &lt;% form_for :user, :url=&gt;{:controller=&gt;'users', :action =&gt; :change_network} do |f| %&gt; &lt;-- this is where the dropdown list etc goes --&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="main"&gt; &lt;%= yield :layout%&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The javascript .rjs.js file contains page.replace_html("site_list_body", :partial => "shared/network_site_list", :locals => {:site_list => @site_list})</p> <p>And the controller code is as follows:</p> <pre><code>def change_network @user = User.find(session[:user_id]) new_network_id=params["user"]["current_network_id"] @user.current_network_id=new_network_id.to_i @site_list=Site.find_all_by_network_id(@user.current_network_id) respond_to do |format| format.js end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload