class Admin::ContactsController < ApplicationController layout "admin" before_filter :auth_admin def index @contacts = Contact.order("created_at DESC").all end def show @contact = Contact.find(params[:id]) if @contact.readed != true @contact.readed = true @contact.save end 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