2

I need this construction in my HAML code:

- if @organisation.type == 'Company'
%p
  %strong Number of Employees:
  = @organisation.number_of_employees
- elsif @organisation.type == 'EducationalInstitution'
%p
  %strong Number of Students
  = @organisation.number_of_students

But i get an Syntax error: Got "elsif" with no preceding "if" How I must to update my code to solve the error?

1 Answer 1

6

Your indentation looks like it might be the issue

- if @organisation.type == 'Company'
  %p
    %strong Number of Employees:
    = @organisation.number_of_employees
- elsif @organisation.type == 'EducationalInstitution'
  %p
    %strong Number of Students
    = @organisation.number_of_students

Bonus indenting quirk

The if/else statement to fail if commenting does not also adhere to the correct indentation.

e.g.

- if @organisation.type == 'Company'
  %p
    %strong Number of Employees:
    = @organisation.number_of_employees

-# Institutional case
- elsif @organisation.type == 'EducationalInstitution'
  %p
    %strong Number of Students
    = @organisation.number_of_students

will fail. Where

- if @organisation.type == 'Company'
  %p
    %strong Number of Employees:
    = @organisation.number_of_employees

- elsif @organisation.type == 'EducationalInstitution'
  -# Institutional case
  %p
    %strong Number of Students
    = @organisation.number_of_students

will is correct.

2
  • you're very welcome.. did that solve the issue? :)
    – ddavison
    Sep 30, 2015 at 12:25
  • excellent.. glad to hear it. go ahead and click the Green checkmark so this question can close
    – ddavison
    Sep 30, 2015 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.