pic_vert_app/app/controllers/admin/faqs_controller.rb
Nicolas Bally 9e3dd91a06 FAQ admin
2015-10-21 16:29:25 +02:00

111 lines
1.4 KiB
Ruby

# -*- encoding : utf-8 -*-
class Admin::FaqsController < ApplicationController
before_filter :auth_admin
layout "admin"
before_filter :find_faqs
def index
end
def cible
render :layout => false
end
def new
@faq = Faq.new
end
def edit
@faq = Faq.find(params[:id])
end
def create
@faq = Faq.new(faq_params)
if @faq.save
flash[:notice] = "L'faq à été ajouté avec succès."
self.find_faqs
else
render :action => "new"
end
end
def update
@faq = Faq.find(params[:id])
if params[:faq]
if @faq.update_attributes(faq_params)
flash[:notice] = "L'faq à été modifié avec succès."
else
render :action => "edit"
end
elsif params[:tag_id]
@faq.tag_by_tag_ids(params[:tag_id])
end
end
def destroy
@faq = Faq.find(params[:id])
@faq.destroy
end
protected
def find_faqs
@faqs = Faq.all
per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 5000
page = (params[:page] and params[:page] != "") ? params[:page] : 1
@faqs = @faqs.page(page).per(per_page)
#@faqs = Event.order('start_at, stop_at').after(start).before(stop)
end
private
def faq_params
params.require(:faq).permit(:author_id, :category_id, :enabled, :published_at, :title, :slug, :tags_cache, :description, :image_file_id, :title_cached)
end
end