1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/controllers/quantities_controller.rb
2019-08-23 17:06:09 +02:00

48 lines
1.1 KiB
Ruby

class QuantitiesController < ApplicationController
before_action :find_project_by_project_id, only: [:index, :create]
before_action :find_quantity, only: [:destroy]
before_action :authorize
def index
@quantity = Quantity.new
@quantities = @project.quantities
end
def create
@quantity = Quantity.new(quantity_params.update(project: @project))
if @quantity.save
flash[:notice] = 'Created new quantity'
redirect_to project_quantities_url(@project)
else
@quantities = @project.quantities
render :index
end
end
def destroy
if @quantity.destroy
flash[:notice] = 'Deleted quantity'
end
redirect_to project_quantities_url(@project)
end
private
def quantity_params
params.require(:quantity).permit(
:name,
:description,
:domain
)
end
# :find_* methods are called before :authorize,
# @project is required for :authorize to succeed
def find_quantity
@quantity = Quantity.find(params[:id])
@project = @quantity.project
rescue ActiveRecord::RecordNotFound
render_404
end
end