user852974
user852974

Reputation: 2282

how to do multiple if statements in rails

        <%- if @last_msg.photo? -%>
            <%= image_tag @last_msg.photo.url(:listsize) %>
        <%- else -%>
            <%= image_tag("default.jpg") %>
        <%- end -%>

Currently this returns either the photo from the last message or a default image, but when a new user creates an account there is no @last_msg so I get a nomethoderror. How can I put in another if statement to say that if there is no last message, then the default image will be returned? Thanks.

Upvotes: 0

Views: 958

Answers (1)

jtbandes
jtbandes

Reputation: 118731

You could try

<% if @last_msg and @last_msg.photo? -%>

Upvotes: 3

Related Questions