title: Rails JavaScript only loads when you Refresh Page, not on the original page load, what's wrong?
body: <h1>The code works when you refresh the page but not on original load.</h1>
  
  <p>Pinterest Clone I'm building. 
  Rails App 4.1.4.</p>
  
  <p>.</p>
  
  <h2>What is supposed to happen</h2>
  
  <p>When you <strong>click a Pin</strong> from the index page, it takes to SHOW page.<br>
  SHOW page has some <strong>JavaScript</strong> which <strong>resizes picture / DIV</strong>.</p>
  
  <p>.</p>
  
  <h2>Problem:</h2>
  
  <p>Almost every time I click a Pin from the index page, the javascript does not run (does not resize the image / div). </p>
  
  <p><strong>BUT</strong> if I click REFRESH with the web browser the script seems to always run just fine (the images / Div get's resized just fine).</p>
  
  <p>.</p>
  
  <p><strong>Link to js on github:</strong>
  <a href="https://github.com/growthcode/pinterest/blob/master/app/assets/javascripts/pins.js.coffee" rel="nofollow">https://github.com/growthcode/pinterest/blob/master/app/assets/javascripts/pins.js.coffee</a></p>
  
  <p><strong>Here it is on Heroku to try it out:</strong>
  <a href="https://growthcode-pinterest.herokuapp.com/" rel="nofollow">https://growthcode-pinterest.herokuapp.com/</a></p>
  
  <p>.</p>
  
  <p><strong>html of the SHOW pin:</strong></p>
  
  <pre><code>&lt;div class="container"&gt;
    &lt;div class="row"&gt;
      &lt;div id="showPinContainer" class="col-xs-12"&gt;
        &lt;div id="showPin" class="well"&gt;
          &lt;%= image_tag @pin.image, class: "show-image" %&gt;
          &lt;p class="description"&gt;&lt;%= @pin.description %&gt;&lt;/p&gt;
          &lt;p&gt;&lt;%= @pin.user.name %&gt;&lt;/p&gt;
          &lt;% if current_user == @pin.user %&gt;
          &lt;%= link_to 'Edit', edit_pin_path(@pin) %&gt; |
          &lt;% end %&gt;
          &lt;%= link_to 'Back', pins_path %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>.</p>
  
  <p>I wrote this in coffee script on rails, I'll list both coffee script and the 'Js2coffee' conversion of it.  </p>
  
  <p><strong>Coffee Script:</strong> </p>
  
  <pre><code># Pin Show page
  $ -&gt;
    # set jQuery object variables
    $windowObj = $(window)
    $showPinContainer = $("#showPinContainer")
    $showPin = $("#showPin")
    $showPinImg = $("#showPin img")
    $showPinHeight = $("#showPin").outerHeight()
    $showPinImgWidth = $showPinImg.outerWidth()
  
    setShowPinContainerHeight = -&gt;
      if $showPinHeight &gt; 450
        $showPinContainer.outerHeight( $showPinHeight )
      else
        $showPinContainer.outerHeight( 450 )
  
    setShowPinContainerWidth = -&gt;
      if $showPinImgWidth &lt; 200
        $showPinImg.outerWidth( 200 )
      else if $showPinImgWidth &gt; 300 
        $showPinImg.outerWidth( 300 )
  
    setShowPinContainerSize = -&gt;
      setShowPinContainerHeight()
      setShowPinContainerWidth()
  
    setShowPinContainerSize()
  </code></pre>
  
  <p>.</p>
  
  <p><strong>The Js2coffee.com conversion of the above coffee script:</strong> </p>
  
  <pre><code>$(function() {
    var $showPin, $showPinContainer, $showPinHeight, $showPinImg, $showPinImgWidth, $windowObj, setShowPinContainerHeight, setShowPinContainerSize, setShowPinContainerWidth;
  
    $windowObj = $(window);
    $showPinContainer = $("#showPinContainer");
    $showPin = $("#showPin");
    $showPinImg = $("#showPin img");
    $showPinHeight = $("#showPin").outerHeight();
    $showPinImgWidth = $showPinImg.outerWidth();
  
    setShowPinContainerHeight = function() {
      if ($showPinHeight &gt; 450) {
        return $showPinContainer.outerHeight($showPinHeight);
      } else {
        return $showPinContainer.outerHeight(450);
      }
    };
  
    setShowPinContainerWidth = function() {
      if ($showPinImgWidth &lt; 200) {
        return $showPinImg.outerWidth(200);
      } else if ($showPinImgWidth &gt; 300) {
        return $showPinImg.outerWidth(300);
      }
    };
  
    setShowPinContainerSize = function() {
      setShowPinContainerHeight();
      return setShowPinContainerWidth();
    };
  
    return setShowPinContainerSize();
  });
  </code></pre>
  
  <hr>
  
  <p>This is my first question on Stack Overflow, so if there is anything else I can provide that would help, please let me know.  Thank you!</p>