faq/app/controllers/faqs_controller.rb

60 lines
1.4 KiB
Ruby

class FaqsController < ApplicationController
def index
faqs = Qa.can_display.order_by(:created_at=>'desc').filter_by_categories.collect do |qa|
statuses = qa.statuses.collect do |status|
{
"status" => status,
"status-class" => "status-#{status.downcase}"
}
end
{
"link_to_show" => OrbitHelper.url_to_show(qa.to_param),
"question" => qa.title,
"statuses" => statuses
}
end
{
"data" => faqs,
"extras" => {"widget-title"=>"Faqs"}
"total_pages" => faqs.total_pages
}
end
def show
params = OrbitHelper.params
faq = Qa.can_display.find_by_param(params[:uid])
faqs_files = faq.qa_files.collect do |f|
{
"file_url" => f.file.url,
"file_title" => f.title
}
end
faqs_links = faq.qa_links.collect do |f|
{
"link_url" => f.url,
"link_title" => f.title
}
end
tags = faq.tags.map{|tag| { "tag" => tag.name } } rescue []
{
"extras" => {"question" => faq.title,"answer" => faq.answer},
"faqs_links" => faqs_links,
"faqs_files" => faqs_files,
"tags" => tags
}
end
def widget
faqs = Qa.filter_by_widget_categories.collect do |qa|
{
"link_to_show" => OrbitHelper.widget_item_url(qa.to_param),
"title" => qa.title,
"postdate" => qa.created_at.strftime('%Y-%m-%d %H:%M')
}
end
{
"faqs" => faqs,
"extras" => {"widget-title"=>"Faqs","more_url"=>OrbitHelper.widget_more_url}
}
end
end