app/controllers/containers_controller.rb
class ContainersController < ApplicationController
before_action :authenticate
before_action :set_container, only: [:show, :edit, :update, :destroy]
# GET /containers
# GET /containers.json
def index
@containers = policy_scope(Container)
end
# GET /containers/1
# GET /containers/1.json
def show
end
# GET /containers/new
def new
@container = Container.new(user_id: current_user.id)
authorize @container
end
# GET /containers/1/edit
def edit
end
# POST /containers
# POST /containers.json
def create
@container = Container.new(container_params)
@container.user = current_user
authorize @container
respond_to do |format|
if @container.save
format.html { redirect_to @container, notice: 'Container was successfully created.' }
else
format.html { render :new }
end
end
end
# PATCH/PUT /containers/1
# PATCH/PUT /containers/1.json
def update
respond_to do |format|
if @container.update(container_params)
format.html { redirect_to @container, notice: 'Container was successfully updated.' }
else
format.html { render :edit }
end
end
end
# DELETE /containers/1
# DELETE /containers/1.json
def destroy
@container.destroy
respond_to do |format|
format.html { redirect_to containers_url, notice: 'Container was successfully destroyed.' }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_container
@container = Container.find(params[:id])
authorize @container
end
# Never trust parameters from the scary internet, only allow the white list through.
def container_params
params.require(:container).permit(:name, :description, :parent_id, :image)
end
end