if else rails 语法错误,意外的“;”,期待“:”
if else rails syntax error, unexpected ';', expecting ':'
我有这个代码:
<% 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 -%>
我想做的是检查我的@lead 是否存在并显示 lead 和一些图片,或者说在 db 中找不到这样的记录。但它给了我一个错误:
/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...
如果我去掉 if else 只留下这个:
<h3>Current status of your car is <%= @lead.status %> </h3><br/><br/>
<%=image_tag("stat/" + @lead.status + ".jpg", :class => "status_image", alt: "status")%>
错误消失。
我该如何解决这个问题?
只需使用这个:
<% 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 %>
这应该可以解决您的问题。
我有这个代码:
<% 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 -%>
我想做的是检查我的@lead 是否存在并显示 lead 和一些图片,或者说在 db 中找不到这样的记录。但它给了我一个错误:
/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...
如果我去掉 if else 只留下这个:
<h3>Current status of your car is <%= @lead.status %> </h3><br/><br/>
<%=image_tag("stat/" + @lead.status + ".jpg", :class => "status_image", alt: "status")%>
错误消失。 我该如何解决这个问题?
只需使用这个:
<% 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 %>
这应该可以解决您的问题。