хамл это все об отступах.Фактическое использование рельсовых помощников и т. Д. Вообще не меняется.Когда вы делаете отступ строкой в 2 пробела, подразумевается, что ваш раздел с отступом содержится в пределах предыдущей строки без отступа.Таким образом, это:
%ul#hello
%li My List Item
Получается так:
<ul id='hello'>
<li>My List Item</li>
</ul>
Это относится и к do
блокам.Если у вас есть помощник по рельсам, вам нужно сделать отступ для блока помощника так же, как и для остальной разметки.Haml автоматически добавит end
, когда отступ будет закончен.Вы должны изменить свою разметку, чтобы она выглядела следующим образом, для ясности я добавил несколько комментариев:
= form_for :booking, :url => booking_path(@booking), :html => { :method => :put } do |form|
%ul
- @booking.errors.full_messages.each do |msg|
-# This is looking good so far... correct indent inside this `do` block
%li= msg
-# I don't feel like we are in the error messages block anymore, but you were still indented here. I've removed the indentation to indicate that we are no longer in that block.
-# This will work fine, but is there a reason you didn't use `form.label :status` here?
= label :booking, :status
= form.text_field :status
-# I've changed this to use `= form.` because I believe the other version (-) is deprecated
= form.fields_for :user do |user_form|
-# You didn't have this indented correctly. To be part of the do block you need to indent it appropriately. Fixed.
= user_form.label :fullname
= user_form.text_field :fullname
-# This is no longer part of the `fields_for` call, so I have removed the indentation again to indicate that this is part of the outer section.
= form.submit "Update this booking"
Надеюсь, это было полезно :) Хамл может показаться немного неловким, но я обнаружил, что он очень помогаетСкорость разработки и мне НАМНОГО проще читать и писать.Это заняло у меня около недели, но оно выросло на меня, и теперь я никогда не буду оглядываться назад: p