nbkkb7x
nbkkb7x

Reputation: 141

Instance Variable If Else Condition to Add Tag in HAML

I am trying to write a conditional statement in my HAML views file. What I would like to do is add a link_to tag on top of the rest of the blockquote if the quote object has link. If it's nil, then format the blockqoute without the link_to tag over top. Here's the current code I have:

.carousel-inner
          - @quotes.each_with_index do |quote, index|
            .item{ class: ("active" if index == 0)}
              - if quote.link.present?
                = link_to quote.link
                  %blockquote
                    .row
                      .col-sm-3.text-center
                        %img.img-circle{:src => quote.avatar, :style => "width: 100px;height:100px;"}
                      .col-sm-9
                        %p= quote.quote
                        %small= quote.author
              - else
                %blockquote
                  .row
                    .col-sm-3.text-center
                      %img.img-circle{:src => quote.avatar, :style => "width: 100px;height:100px;"}
                    .col-sm-9
                      %p= quote.quote
                      %small= quote.author

The current stack error I'm getting is:

_quotes.html.haml:26: syntax error, unexpected keyword_else, expecting keyword_end _quotes.html.haml:39: syntax error, unexpected keyword_ensure, expecting end-of-input

Rails Error Image

Anyone run into something like this before? Thanks!

Upvotes: 1

Views: 407

Answers (1)

matt
matt

Reputation: 79723

You are missing the do from the line = link_to quote.link which is throwing the parsing of ending blocks off. You just need to change it to:

= link_to quote.link do
  %blockquote
    -# ...

Upvotes: 1

Related Questions