Haml's verbose comments and if-elsif-else statement

I have the following code.

- if specializations.count <= 0
  .alert.alert-warning
    Warning message

-# - elsif agency.offers_limit >= agency.offers.count
-#   .alert.alert-warning
-#     Warning message

- else
  = render 'form'

In this case, I get Got "else" with no preceding "if". How else can I comment on part of the already commented code to - else ...be processed correctly?

If I comment on the code as follows:

- if specializations.count <= 0
  .alert.alert-warning
    Warning message

-# - elsif agency.offers_limit >= agency.offers.count
  .alert.alert-warning
    Warning message

- else
  = render 'form'

I have no error, but it is - else ...not being processed and the form is not displayed.

+4
source share
1 answer

Code that should not be processed in the statement if - elsif - elsemust be indented . So, if in my case I want to skip the instruction elsif, my code should look like this:

- if specializations.count <= 0
  .alert.alert-warning
    Warning message 

  -# - elsif agency.offers_limit >= agency.offers.count
  -#  .alert.alert-warning
  -#    Warning message

- else
  = render 'form'

( ):

- if specializations.count <= 0
  .alert.alert-warning
    Warning message 

  -# - elsif agency.offers_limit >= agency.offers.count
    .alert.alert-warning
      Warning message

- else
  = render 'form'
+4

All Articles