if else rails语法错误,意外';',期待':'

时间:2016-01-26 04:08:26

标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-3.2

我有这段代码:

<% 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是否存在并显示铅和一些图片,或者说没有找到db中的这些记录。但它给了我一个错误:

  

/home/jonstark/rails_projects/car_main/app/views/static_pages/check_lead_car_status.html.erb:4:   语法错误,意外';',期待':'...你的状态   汽车是'; @ output_buffer.append =(@ lead ...

如果我带走了别的东西而且只留下这个:

<h3>Current status of your car is <%= @lead.status %> </h3><br/><br/>
        <%=image_tag("stat/" + @lead.status + ".jpg", :class => "status_image", alt: "status")%>

错误消失了。 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

请使用:

<% 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 %>

这应该可以解决您的问题。