Note that there are some explanatory texts on larger screens.

plurals
  1. PORails keep if false, render if true
    text
    copied!<p>I have a div tag that I want to change only if a function returns true, otherwise I want it to keep the same content. I used <code>render: nothing =&gt; true</code> but that removes everything.</p> <pre><code>&lt;%= javascript_include_tag :defaults %&gt; &lt;div id="x"&gt;Hi&lt;/div&gt; &lt;% form_remote_tag :url =&gt; {:action =&gt; 'get'}, :update =&gt; 'x' do %&gt; &lt;%= text_field_tag 'url' %&gt; &lt;%= submit_tag "Submit" %&gt; &lt;% end %&gt; def getImage @img = params[:url] if !verify @img render :nothing =&gt; true end end private def verify url return true if url =~ /https?:\/\/.*\.(jpg|png|gif|bmp)$/ return false end </code></pre> <p>I want to make my rails code do this</p> <pre><code>var lastrequest = ""; function ajaxObj() { //Returns the ajax object based on browser if ( window.XMLHttpRequest ) { return new XMLHttpRequest(); //Firefox } else if ( window.ActiveXObject ) { return new ActiveXObject("Microsoft.XMLHTTP"); //IE } } window.onload = function() { document.getElementById("Submit").onclick = function() { var request = ajaxObj(); request.onreadystatechange = function() { if ( request.readyState == 4 ) { document.getElementById("imgdisplay").innerHTML = request.responseText; document.getElementById("imgurl").value = ""; } } if ( lastrequest != document.getElementById("imgurl").value ) { // Makes sure it doesn't request the same image twice var parameters = "url=" + document.getElementById("imgurl").value; request.open("POST", "imageget.php", true); // Sends the ajax request request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestHeader("Content-length", parameters.length); request.setRequestHeader("Connection", "close"); request.send(parameters); lastrequest = document.getElementById("imgurl").value; } } } </code></pre>
 

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