80 lines
1.2 KiB
Ruby
80 lines
1.2 KiB
Ruby
class Admin::ContactsController < ApplicationController
|
|
layout "admin"
|
|
|
|
before_filter :auth_admin
|
|
|
|
def index
|
|
|
|
@contacts = Contact.order("created_at DESC")
|
|
|
|
if params[:archived]
|
|
@contacts = @contacts.where(:archived => true)
|
|
else
|
|
@contacts = @contacts.where("archived IS NULL or archived = 0")
|
|
end
|
|
|
|
end
|
|
|
|
|
|
def show
|
|
@contact = Contact.find(params[:id])
|
|
|
|
if @contact.readed != true
|
|
@contact.readed = true
|
|
@contact.save
|
|
end
|
|
|
|
@contact_actions = @contact.contact_actions
|
|
|
|
end
|
|
|
|
|
|
def new
|
|
@contact = Contact.new
|
|
|
|
end
|
|
|
|
def edit
|
|
@contact = Contact.find(params[:id])
|
|
|
|
end
|
|
|
|
def create
|
|
@contact = Contact.new(contact_params)
|
|
|
|
if @contact.save
|
|
@contacts = Contact.order("created_at DESC").all
|
|
else
|
|
render :action => "new"
|
|
end
|
|
end
|
|
|
|
def update
|
|
@contact = Contact.find(params[:id])
|
|
|
|
if @contact.update_attributes(contact_params)
|
|
|
|
else
|
|
render :action => "edit"
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
@contact = Contact.find(params[:id])
|
|
|
|
@contact.destroy if @contact != @current_contact
|
|
|
|
end
|
|
|
|
private
|
|
def contact_params
|
|
params.require(:contact).permit!
|
|
end
|
|
|
|
|
|
|
|
end
|