55 lines
1.1 KiB
Ruby
55 lines
1.1 KiB
Ruby
class Public::NeedsController < ApplicationController
|
|
|
|
layout "public"
|
|
|
|
before_filter :auth_customer
|
|
|
|
def new
|
|
@need = Need.new()
|
|
end
|
|
|
|
def destroy
|
|
@need = Need.find(params[:id])
|
|
if(@need.destroy)
|
|
flash[:notice] = "Besoin supprimé avec succès."
|
|
end
|
|
redirect_to public_my_account_path
|
|
end
|
|
|
|
def edit
|
|
@need = Need.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
@need = Need.find(params[:id])
|
|
if @need.update_attributes(need_params)
|
|
flash[:notice] = "Besoin sauvegardé avec succès."
|
|
redirect_to public_my_account_path
|
|
else
|
|
render :action => "edit"
|
|
end
|
|
end
|
|
|
|
def create
|
|
@need = Need.new(need_params)
|
|
@need.author = current_customer
|
|
if @need.save
|
|
flash[:notice] = "Votre besoin à été créé avec succès."
|
|
|
|
# Find all admins with emails
|
|
admins = Admin.where.not(email: nil)
|
|
admins.each do |admin|
|
|
AdminMailer.new_need(admin, @need).deliver
|
|
end
|
|
redirect_to public_my_account_path
|
|
else
|
|
render :action => "new"
|
|
end
|
|
end
|
|
|
|
def need_params
|
|
params.require(:need).permit(:title, :description)
|
|
end
|
|
|
|
end
|