added scope and few mods in controller

This commit is contained in:
Harry Bomrah 2014-06-18 14:41:43 +08:00
parent c15ed696b8
commit 96a612af50
2 changed files with 7 additions and 3 deletions

View File

@ -1,6 +1,7 @@
class FaqsController < ApplicationController
def index
faqs = Qa.can_display.order_by(:created_at=>'desc').filter_by_categories.collect do |qa|
faqs = Qa.can_display.order_by(:created_at=>'desc').filter_by_categories
f = faqs.collect do |qa|
statuses = qa.statuses.collect do |status|
{
"status" => status,
@ -14,8 +15,8 @@ class FaqsController < ApplicationController
}
end
{
"data" => faqs,
"extras" => {"widget-title"=>"Faqs"}
"data" => f,
"extras" => {"widget-title"=>"Faqs"},
"total_pages" => faqs.total_pages
}
end

View File

@ -23,6 +23,9 @@ class Qa
accepts_nested_attributes_for :qa_files, :allow_destroy => true
accepts_nested_attributes_for :qa_links, :allow_destroy => true
scope :can_display, ->{where(:is_hidden=>false).order_by([:is_top, :desc])}
# belongs_to :qa_category
before_save :clean_values