-1

It's Eco, the problem is it should add button just for some models(backbone) in partial, but the statment if not worked.The variables are accessible, but the owner.id a is string and current_user.id is a number.

<% if @owner?.id is current_user.id: %>
    <div class="info-add">
       <button class="button secondary tiny radius">
           <i class="fi-plus"></i>
           Add
       </button>
   </div>
<% end %>
tenaz3.comp
  • 367
  • 6
  • 17

1 Answers1

1

Eco uses CoffeeScript as the template language and in CoffeeScript, is and == become === in the JavaScript version. JavaScript's strict equality operator (===) doesn't do the type conversions that == will do so '6' === 6 is false even though '6' == 6 is true.

You say that:

the owner.id a is string and current_user.id is a number

so @owner.id is current_user.id will always be false.

If your client code is generating the id as a string then it is broken and you should fix it. If your server is sending @owner.id as a string then your server is broken and you should fix your server to send out the correct JSON; if you can't fix the server code then you could add a parse method to your model to fix it for you:

parse: function(response) {
    if(response.id)
        response.id = +response.id // or parseInt(response.id, 10) if you prefer
    return response;
}
mu is too short
  • 426,620
  • 70
  • 833
  • 800