I’m trying to use coffescript as views in Rails 3.2.11
I have create.js.coffee with the following lines:
is_valid = <%=@model.valid?%>
if is_valid
res = confirm("Are you sure you want to continue?")
if(res)
<%=@model.activate%>
window.location.href = "/blabla/models"
else
return
else
$('.form .field_with_errors').removeClass('field_with_errors')
jw_funcs.respond_with_error(<%=@response_invalid%>)
The problem is that the line of code <%=@model.activate%>
is executed every time. I think it depends on the fact that the erb engine runs independently from the coffee engine; If so, how can I do this ?
You really weren’t expecting this coffee code to call your model method from the client’s browser, were you?
Wrap
@model.activateinto its own controller action, which will be called by clients if the confirmation is given. Something like this: