impress/app/controllers/closet_lists_controller.rb
Matchu d97c32b5da Upgrade to Rails 5.2.8.1
Some important little upgrades but mostly straightforward!

Note that there's still a known issue where item searches crash, I was hoping that this was a bug in Rails 4.2 that would be fixed on upgading to 5, but nope, oh well!

Also uhh I just got a bit silly and didn't actually mean to go all the way to 5.2 in one go, I had meant to start at 5.0… but tbh the 5.1 and 5.2 changes seem small, and this seems to be working, so. Yeah ok let's roll!
2023-10-23 19:05:05 -07:00

54 lines
1.3 KiB
Ruby

class ClosetListsController < ApplicationController
before_action :authorize_user!
before_action :find_closet_list, :only => [:edit, :update, :destroy]
def create
@closet_list = current_user.closet_lists.build closet_list_params
if @closet_list.save
save_successful!
else
save_failed!
render :action => :new
end
end
def destroy
@closet_list.destroy
flash[:success] = "Successfully deleted \"#{@closet_list.name}\""
redirect_to user_closet_hangers_path(current_user)
end
def new
@closet_list = current_user.closet_lists.build closet_list_params
end
def update
if @closet_list.update_attributes(closet_list_params)
save_successful!
else
save_failed!
render :action => :edit
end
end
protected
def closet_list_params
params.require(:closet_list).permit(
:description, :hangers_owned, :name, :visibility)
end
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!
flash[:success] = "Successfully saved \"#{@closet_list.name}\""
redirect_to user_closet_hangers_path(current_user)
end
end