Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How HAML can recognize the end of the block?

= form_for(:subject, :url => {:action => "create"}) do |f|
    = render :partial => "form", :locals => {:f => f}
    #form_buttons= submit_tag "Create Subject"

Noticed that form_for has a "do",so it needs a "end", but how does HAML knows where to end the "end" ?

Sorry about my English,hope you can understand what am I talking about!

like image 296
Hugh Avatar asked Nov 21 '25 16:11

Hugh


2 Answers

HAML uses indentation to delimit blocks in the same way the Python language does. Perhaps you should read a basic tutorial or WIKI for more information.

= form_for(:subject, :url => {:action => "create"}) do |f|
    = render :partial => "form", :locals => {:f => f}
    #you can use f here
# you can't use f here
like image 57
retro Avatar answered Nov 24 '25 08:11

retro


HAML uses indentation for block structure.
More simply put, when the code actually 'outdents' it's an implied end (either to the html tag OR the ruby do-end block). So what in html/ruby would be

...
loop1
  loop2
    code_for_loop2
  end # of loop2
end # of loop1
...

in haml becomes
...
loop1
  loop2
    code for loop2
...

p.s. indent by 2 also, spaces not tabs.

like image 27
Michael Durrant Avatar answered Nov 24 '25 07:11

Michael Durrant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!