2011-07-26 17:27:23 -07:00
|
|
|
class ClosetListsController < ApplicationController
|
2023-08-02 16:05:02 -07:00
|
|
|
before_action :authorize_user!
|
|
|
|
before_action :find_closet_list, :only => [:edit, :update, :destroy]
|
2011-07-26 17:27:23 -07:00
|
|
|
|
|
|
|
def create
|
2023-07-29 11:22:15 -07:00
|
|
|
@closet_list = current_user.closet_lists.build closet_list_params
|
2011-07-26 17:27:23 -07:00
|
|
|
if @closet_list.save
|
2011-07-29 07:52:04 -07:00
|
|
|
save_successful!
|
2011-07-26 17:27:23 -07:00
|
|
|
else
|
2011-07-29 07:52:04 -07:00
|
|
|
save_failed!
|
2011-07-26 17:27:23 -07:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
2011-07-29 07:52:04 -07:00
|
|
|
|
|
|
|
def destroy
|
|
|
|
@closet_list.destroy
|
2023-08-06 17:33:57 -07:00
|
|
|
flash[:notice] = "Successfully deleted \"#{@closet_list.name}\""
|
2011-07-29 07:52:04 -07:00
|
|
|
redirect_to user_closet_hangers_path(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2023-07-29 11:22:15 -07:00
|
|
|
@closet_list = current_user.closet_lists.build closet_list_params
|
2011-07-29 07:52:04 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2023-08-06 15:56:28 -07:00
|
|
|
@closet_list.attributes = closet_list_params
|
|
|
|
if @closet_list.save
|
2011-07-29 07:52:04 -07:00
|
|
|
save_successful!
|
|
|
|
else
|
|
|
|
save_failed!
|
|
|
|
render :action => :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2023-07-29 11:22:15 -07:00
|
|
|
def closet_list_params
|
|
|
|
params.require(:closet_list).permit(
|
|
|
|
:description, :hangers_owned, :name, :visibility)
|
|
|
|
end
|
|
|
|
|
2011-07-29 07:52:04 -07:00
|
|
|
def find_closet_list
|
|
|
|
@closet_list = current_user.closet_lists.find params[:id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def save_failed!
|
|
|
|
flash.now[:alert] = "We can't save this list because: #{@closet_list.errors.full_messages.to_sentence}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def save_successful!
|
2023-08-06 17:33:57 -07:00
|
|
|
flash[:notice] = "Successfully saved \"#{@closet_list.name}\""
|
2011-07-29 07:52:04 -07:00
|
|
|
redirect_to user_closet_hangers_path(current_user)
|
|
|
|
end
|
2011-07-26 17:27:23 -07:00
|
|
|
end
|
|
|
|
|