开发者

How do you find and loop through a subset of an array in a haml view?

Here are my models and controllers:

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 :answ开发者_运维百科er, :presence=>true

end

class HelpController < ApplicationController
  def faqs
    @faq_categories=FaqCategory.roots.order(:title)
    @faqs=Faq.all();
  end
end

And here is the haml view I am attempting to build. Basically I am looping through @faq_categories and in each loop I want to find all the @faqs that are in that cat and display them.

.unibody
    .content
        .inner-content
            -   @faq_categories.each do |cat|
                = cat.title
                    - @faqs.find_all{|faq| faq.faq_category==cat}.each do |thisfaq|
                        = thisfaq.question

I get this error (I'm new to haml and rails and am probably missing something simple):

12: syntax error, unexpected keyword_ensure, expecting $end


There is something weird about your nesting. Try this:

.unibody
    .content
        .inner-content
            - @faq_categories.each do |cat|
                = cat.title
                - @faqs.find_all{|faq| faq.faq_category==cat}.each do |thisfaq|
                    = thisfaq.question
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜