简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM