0

I have a function in a rails app that is activated onclick from a drop-down menu. The file the function is in dashboards.js.coffee is recognized but the dropdown keeps giving me the error

Uncaught ReferenceError: chooseManager is not defined

Here is the drop-down menu that has the chooseManager call...

   <select id="adminDropDown" onchange= "chooseManager();" class="form-control">
        <% if current_admin.manager_approvals.blank? %>
           <option>No Sub-Accounts added, Add one today!</option>
        <% elsif current_admin.manager_approvals.all? { |ma| ma.manager_approved == false }%>
           <option>No Sub-Accounts approved yet!</option>
        <% else %>
           <% current_admin.manager_approvals.where(manager_approved: true).each do |ma| %>
            <option value="<%= ma.manager_id %>"><%= ma.manager_company %>&nbsp;|&nbsp;<%= number_to_phone(ma.manager_phone) %></option>
        <% end %>
      <% end %>
  </select>

Here is the coffescript function...

chooseManager = ->
 managerId = $(this).val()
 $.ajax
 type: 'POST'
 url: 'admins/reportapprovals/manager_select'
 data: manager_id: managerId
return

I am not well versed in coffescript, what am I missing or doing wrong?

SupremeA
  • 1,519
  • 3
  • 26
  • 43
  • 1
    Executive summary: You want to say `@chooseManager = -> ...` to break `chooseManager` out of the scope guard that CoffeeScript wraps everything in. Also, be very careful with the indentation in your CoffeeScript, that's pretty much all you have for defining your code's structure so it has to be right and consistent. – mu is too short May 28 '16 at 18:54
  • Got it. I will have to find some better resources on coffeescript and read up. Thanks @muistooshort! – SupremeA May 28 '16 at 19:27

0 Answers0