[英]if else rails syntax error, unexpected ';', expecting ':'
I have this code: 我有以下代码:
<% if @lead? -%>
<h3>Current status of your car is <%= @lead.status %> </h3>
<%=image_tag("stat/" + @lead.status + ".jpg", :class => "status_image", alt: "status")%>
<% else -%>
<h3> No records found.</h3>
<% end -%>
What I want to do is to check if my @lead exists and show lead and some picture or say that such records in db were not found. 我想要做的是检查我的@lead是否存在并显示Lead和一些图片,或者说找不到db中的此类记录。 But it gives me an error:
但这给了我一个错误:
/home/jonstark/rails_projects/car_main/app/views/static_pages/check_lead_car_status.html.erb:4: syntax error, unexpected ';', expecting ':' ...urrent status of your car is ';@output_buffer.append=( @lead...
/home/jonstark/rails_projects/car_main/app/views/static_pages/check_lead_car_status.html.erb:4:语法错误,意外出现“;”,期望出现“:” ...您汽车的当前状态为“; @ output_buffer.append =(@铅...
If I take away if else and leave just this: 如果我带走了,就别这样:
<h3>Current status of your car is <%= @lead.status %> </h3><br/><br/>
<%=image_tag("stat/" + @lead.status + ".jpg", :class => "status_image", alt: "status")%>
The error dissapears. 错误消失了。 How do I fix this?
我该如何解决?
Just use this: 只需使用此:
<% if @lead %>
<h3>Current status of your car is <%= @lead.status %> </h3>
<%=image_tag("stat/" + @lead.status + ".jpg", :class => "status_image", alt: "status")%>
<% else %>
<h3> No records found.</h3>
<% end %>
This should work and fix your problem. 这应该可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.