class Public::NeedsController < ApplicationController layout "public" before_filter :auth_customer def index @needs = Need.shared end 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 def wish @need = Need.find(params[:id]) if (!@need.customers.include?(current_customer)) @need.customers << current_customer flash[:notice] = "Vous avez signalé votre intérêt pour ce besoin" else @need.customers.delete(current_customer) flash[:error] = "Vous n'être plus marqué comme intéressé par ce besoin" end redirect_to :back end end