how to call cosine and sine function in .html.erb file?
My form calls trig functions like sin and cos, but I'm unable 开发者_如何学编程to compile it ; it keeps returning me this error message
undefined method `cos' for #<#<Class:0x10345d6d0>:0x1034488c0>
How can I fix this error ?
I am unable to paste my code to this window, but I have "include Math" and
<% @project.UsableArea = @project.DevelopableRoofArea / (cos(@project.TiltAngle) + 3 * sin(@project.TiltAngle)) %>
You need to prefix the cos
and sin
methods with the module name:
Example:
<%= Math.cos(0.5) %>
In your case:
<% @project.UsableArea = @project.DevelopableRoofArea / (Math.cos(@project.TiltAngle) + 3 * Math.sin(@project.TiltAngle)) %>
精彩评论