以下是我的模型和控制器:
class FaqCategory < ActiveRecord::Base
has_many :faqs, dependent: :restrict, inverse_of: :faq_category
validates :title, :presence=>true, uniqueness: {scope: :ancestry}
end
class Faq < ActiveRecord::Base
belongs_to :faq_category, inverse_of: :faqs
validates :question, :presence=>true
validates :answer, :presence=>true
end
class HelpController < ApplicationController
def faqs
@faq_categories=FaqCategory.roots.order(:title)
@faqs=Faq.all();
end
end
这是我正在尝试构建的haml视图。基本上我循环遍历@faq_categories并且在每个循环中我想找到该猫中的所有@faq并显示它们。
.unibody
.content
.inner-content
- @faq_categories.each do |cat|
= cat.title
- @faqs.find_all{|faq| faq.faq_category==cat}.each do |thisfaq|
= thisfaq.question
我收到了这个错误(我是haml和rails的新手,可能会遗漏一些简单的事情):
12:语法错误,意外的keyword_ensure,期待$ end
答案 0 :(得分:0)
你的筑巢有些奇怪。试试这个:
.unibody
.content
.inner-content
- @faq_categories.each do |cat|
= cat.title
- @faqs.find_all{|faq| faq.faq_category==cat}.each do |thisfaq|
= thisfaq.question