sleeping_dragon
sleeping_dragon

Reputation: 711

Coffeescript unexpected terminator error

I have this in my /assets/javascripts/leads.js.coffee

jQuery ->
  getRowColour = (status) ->
    switch status
    when "rejected" then return '#FFA500'
    when "confirmed" then return '#C0C0C0'
    when "didn't connect" then return '#90EE90'
    else return '#FFFFFF'

and this in my /views/leads/index.html.erb

<%= f.select(:status, ["to call","didn't connect","confirmed","rejected"], {:selected => lead.status}, :onchange => "$('#lead_form_#{lead.id}').submit();document.getElementById('lead_row_#{lead.id}').style.backgroundColor=getRowColour(#{lead.status});") %>
        <% end %> 

As can be seen my onchange function in f.select has a javascript which calls the function in my coffeescript file.

Please tell me where I am going wrong?

Upvotes: 0

Views: 5932

Answers (1)

Dogbert
Dogbert

Reputation: 222398

when and else statements need to be indented one level more than switch.

jQuery ->
  getRowColour = (status) ->
    switch status
      when "rejected" then return '#FFA500'
      when "confirmed" then return '#C0C0C0'
      when "didn't connect" then return '#90EE90'
      else return '#FFFFFF'

Also, switch is an expression in CoffeeScript, and the last expression in your function, you don't need to add return after when.

Upvotes: 7

Related Questions