I am running jQuery in app/assets/javascripts/ticket.js.coffeefor a specific view. Every time I visit a page, the browser makes this error - this error is not mentioned anywhere on the Internet.
(local: 3000 / tickets / new)
SyntaxError: unexpected POST_IF
Extracted source (around line
3: <head>
4: <title>Ops2</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
Error Page File -
application / views / tickets / _form.html.erb
<%= form_for(@ticket) do |f| %>
<% if @ticket.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@ticket.errors.count, "error") %> prohibited this ticket from being saved:</h2>
<ul>
<% @ticket.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :school_id %><br />
<%= f.collection_select :school_id, School.order(:name), :id, :name, include_blank: true%>
</div>
<div class="field">
<%= f.label :location_id %><br />
<%= f.grouped_collection_select :location_id, School.order(:name), :locations, :name, :id, :name, include_blank: true%>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
app / assets / javascripts / application.js contains:
Coffeescript file with jQuery -
application / assets / JavaScripts / tickets.js.coffee
$ ->
$('#ticket_location_id').parent().hide()
locations = $('#ticket_location_id').html()
$('#ticket_school_id').change ->
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()
The POST_IF error was resolved by indenting statements if / elsein my coffee script! (for more details see the answer below) There are no errors and the page is loading!
source
share