jquery - SyntaxError: unexpected POST_IF error Rails -
i'm running jquery in app/assets/javascripts/ticket.js.coffee
specific view. every time visit page browser renders error - there no mention of error anywhere online.
(localhost:3000/tickets/new):
syntaxerror: unexpected post_if extracted source (around line #6): 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>
file of page throwing error -
app/views/tickets/_form.html.erb:
<%= form_for(@ticket) |f| %> <% if @ticket.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@ticket.errors.count, "error") %> prohibited ticket being saved:</h2> <ul> <% @ticket.errors.full_messages.each |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:
//= require jquery //= require jquery_ujs //= require_tree .
coffeescript file jquery -
app/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 has been resolved indenting if / else
statements in coffee script! (see answer below details) there no errors , page loads!
you're missing indentation if
statement. indentation crucial in coffeescript.
this...
if options $('#ticket_location_id').html(options) $('#ticket_location_id').parent().show() else $('#ticket_location_id').empty $('#ticket_location_id').parent().hide()
... needs this, leading indentation not optional:
if options $('#ticket_location_id').html(options) $('#ticket_location_id').parent().show() else $('#ticket_location_id').empty $('#ticket_location_id').parent().hide()
Comments
Post a Comment