【问题标题】:haml and Getting Started with Rails RailsGuideshaml 和 Rails 入门 RailsGuides
【发布时间】:2011-12-23 08:28:23
【问题描述】:

无法弄清楚为什么我的标签没有显示在新建和编辑视图中使用的表单中。我只能看到 %h2 标签。 after 声明的部分根本不生成。

这就是我所拥有的。我错过了什么? (_form.html.haml)

=form_for @post do |form|
.
.
.
%p
  =form.label :content
  %br
  =form.text_area :content

%h2
  Tags
= render :partial => 'tags/form', :locals => {:form => form}

%p
  =form.submit

表单位于 app/views/tags _form.html.haml。 这些都没有出现:

= form.fields_for :tags do |tag_form|
  .field
    = tag_form.label :name, 'Tag:'
    = tag_form.text_field :name
  - unless tag_form.object.nil? || tag_form.object.new_record?
    .field
      = tag_form.label :_destroy, 'Remove:'
      = tag_form.check_box :_destroy

或者如果它不在这里。我还应该去哪里看?

谢谢!

【问题讨论】:

  • 当你说“app/views/tags _form.html.haml”时,你的意思是“app/views/tags/_form.html.haml”对吧?

标签: ruby-on-rails ruby haml render partial


【解决方案1】:

根据您使用的 Rails 版本,您需要进行许多更改:

= form.fields_for :tags do |tag_form|

- form.fields_for :tags do |tag_form|

【讨论】:

    【解决方案2】:

    或者你应该缩进

    = render :partial => 'tags/form', :locals => {:form => form}

    右边还有两个空格,以便它在表单内

    【讨论】:

      猜你喜欢
      • 2011-10-11
      • 2016-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-19
      • 2011-02-13
      相关资源
      最近更新 更多