Why is this block of haml code giving 'syntax error, unexpected keyword_ensure, expecting $end'

= tabs_tag(:open_tabs => { :id => "menu" }) do |tab| 
  - menu_tabs.each do |menu_tab|
    - if !menu_tab.only_if.nil?
      - if menu_tab.only_if.call
        = tab.send menu_tab.tab_name, menu_tab.display_name, menu_tab.path, :span => "arrow-down"
          - if !menu_tab.child_elements.blank?
            %ul
            - menu_tab.child_elements.each do |child_tab|
              %li
                =link_to child_tab.display_name, child_tab.path
    - else
      = tab.send menu_tab.tab_name, menu_tab.display_name, menu_tab.path

The error message is

app/views/menu_builder/_tab_view.html.haml:15: syntax error, unexpected keyword_else, expecting keyword_end
app/views/menu_builder/_tab_view.html.haml:21: syntax error, unexpected keyword_ensure, expecting $end

(btw the line numbers are wrong too, I don't know if this is a haml thing)

I have checked the indentation and everything should be correct, and that else should correspond to if !menu_tab.only_if.nil?, so I don't understand why this error message is appearing.

Answers


I'm guessing it's because you're doing this:

= tabs_tag(:open_tabs => { :id => "menu" }) do |tab| 

and

= tab.send menu_tab.tab_name, menu_tab.display_name, menu_tab.path, :span => "arrow-down"

and then nesting content under that which is illegal in HAML. You get the same error when you try to do:

= render :partial => "some/view", :locals => { :local_var => @var }
  - if something
    -# do something

HAML will choke on that since it doesn't know how to render the if statement within the partial file (based on spacing, location of the if statement within it, etc.). Same thing applies with other code helpers like the tabs you're using.


Need Your Help

Java Reflection, Class Objects

java class reflection

My objective is to read in to the command line the name of a Class I wish to observe info on. When I know the class name before runtime, I have no issue. What I can't seem to manage is how to cre...

ASP.NET MVC n-tier Architecture - Best Solution

.net asp.net-mvc web-applications architecture saas

We are currently designing an ERP solution which will be built on ASP.NET MVC4. The system has modules (Say HR, Sales & Production) which will need to work independent of each other.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.