rails 3.1,simple_form,使用haml?

时间:2011-11-04 04:21:14

标签: ruby-on-rails-3 haml simple-form

我如何在haml中编写这个simple_form:

<%= simple_form_for (@quiz) do |f| %>
<%= f.error_notification %>
  <div class="inputs">
    <%= f.input :body %>
    <%= f.fields_for :quiz_choices do |builder| %>
         <%= render "quiz_choice_fields", :f => builder %>
    <% end %>
    <p><%= link_to_add_association  "Add a choice",f, :quiz_choices %></p>
  </div>

  <div class="actions">
    <%= f.button :submit %>
  </div>
<% end %>

这是我的尝试:

- simple_form_for (@quiz) do |f|
- f.error_notification
  .inputs
    = f.input :body
    - f.fields_for :quiz_choices do |builder|
    = render "quiz_choice_fields", :f => builder

    %p= link_to_add_association  "Add a choice",f, :quiz_choices
  .actions
    = f.button :submit

这是错误:

提取的来源(第12行):

9:   .actions
10:     = f.button :submit

1 个答案:

答案 0 :(得分:4)

好的,只要你<%=,就应该成为= haml,而不是-。此外,对于循环或块,您需要缩进其下的代码。

- simple_form_for (@quiz) do |f|
- f.error_notification
  .inputs
    = f.input :body
    - f.fields_for :quiz_choices do |builder|
    = render "quiz_choice_fields", :f => builder

    %p= link_to_add_association  "Add a choice",f, :quiz_choices
  .actions
    = f.button :submit

应该成为:

= simple_form_for (@quiz) do |f|
  = f.error_notification
  .inputs
    = f.input :body
    = f.fields_for :quiz_choices do |builder|
      = render "quiz_choice_fields", :f => builder
    %p= link_to_add_association  "Add a choice",f, :quiz_choices
  .actions
    = f.button :submit