title: SyntaxError: unexpected POST_IF error Rails
body: <p>I'm running jQuery in <code>app/assets/javascripts/ticket.js.coffee</code> for a specific view. Every time I visit the page the browser renders this error - there is no mention of this error anywhere online.</p>
  
  <p><strong>(localhost:3000/Tickets/new)</strong>:</p>
  
  <pre><code>SyntaxError: unexpected POST_IF
  
  Extracted source (around line #6):
  
  3: &lt;head&gt;
  4:   &lt;title&gt;Ops2&lt;/title&gt;
  5:   &lt;%= stylesheet_link_tag    "application", :media =&gt; "all" %&gt;
  6:   &lt;%= javascript_include_tag "application" %&gt;
  7:   &lt;%= csrf_meta_tags %&gt;
  8: &lt;/head&gt;
  9: &lt;body&gt;
  </code></pre>
  
  <p>File of the page throwing the error - </p>
  
  <p><strong>app/views/tickets/_form.html.erb</strong>:</p>
  
  <pre><code>&lt;%= form_for(@ticket) do |f| %&gt;
  &lt;% if @ticket.errors.any? %&gt;
  &lt;div id="error_explanation"&gt;
  &lt;h2&gt;&lt;%= pluralize(@ticket.errors.count, "error") %&gt; prohibited this ticket from being saved:&lt;/h2&gt;
  &lt;ul&gt;
  &lt;% @ticket.errors.full_messages.each do |msg| %&gt;
  &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
  &lt;% end %&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  
  &lt;div class="field"&gt;
  &lt;%= f.label :school_id %&gt;&lt;br /&gt;
  &lt;%= f.collection_select :school_id, School.order(:name), :id, :name, include_blank: true%&gt;
  &lt;/div&gt;
  
  &lt;div class="field"&gt;
  &lt;%= f.label :location_id %&gt;&lt;br /&gt;
  &lt;%= f.grouped_collection_select :location_id, School.order(:name), :locations, :name, :id, :name, include_blank: true%&gt;
  &lt;/div&gt;
  
  &lt;div class="actions"&gt;
  &lt;%= f.submit %&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>app/assets/javascripts/application.js</strong> contains:</p>
  
  <pre><code>//= require jquery
  //= require jquery_ujs
  //= require_tree .
  </code></pre>
  
  <p>Coffeescript file with jQuery - </p>
  
  <p><strong>app/assets/javascripts/tickets.js.coffee</strong>:</p>
  
  <pre><code>$ -&gt;
  $('#ticket_location_id').parent().hide()
    locations = $('#ticket_location_id').html()
  $('#ticket_school_id').change -&gt;
    school = $('#ticket_school_id :selected').text()
    options = $(locations).filter("optgroup[label='#{school}']").html()
  if options
  $('#ticket_location_id').html(options)
  $('#ticket_location_id').parent().show()
  else
  $('#ticket_location_id').empty
  $('#ticket_location_id').parent().hide()
  </code></pre>
  
  <p>The POST_IF error has been resolved by indenting the <code>if / else</code> statements in my coffee script! (see answer below for details) There are no errors and the page loads!</p>