Rubocop rules

This commit is contained in:
Nedim
2025-02-17 19:12:40 +01:00
parent ef01db0700
commit ee89170c32
42 changed files with 1043 additions and 267 deletions

View File

@@ -1,6 +1,6 @@
class ApplicationController < ActionController::Base
private
def set_company
company_id = session.fetch(:company_id, Company.first&.id)
session[:company_id] = company_id

View File

@@ -1,5 +1,5 @@
class CompaniesController < ApplicationController
before_action :set_company, only: %i[ show edit update destroy ]
before_action :set_company, only: %i[show edit update destroy]
# GET /companies or /companies.json
def index
@@ -7,8 +7,7 @@ class CompaniesController < ApplicationController
end
# GET /companies/1 or /companies/1.json
def show
end
def show; end
# GET /companies/new
def new
@@ -16,8 +15,7 @@ class CompaniesController < ApplicationController
end
# GET /companies/1/edit
def edit
end
def edit; end
# POST /companies or /companies.json
def create
@@ -25,7 +23,7 @@ class CompaniesController < ApplicationController
respond_to do |format|
if @company.save
format.html { redirect_to company_url(@company), notice: "Company was successfully created." }
format.html { redirect_to company_url(@company), notice: t('.company_created') }
format.json { render :show, status: :created, location: @company }
else
format.html { render :new, status: :unprocessable_entity }
@@ -38,7 +36,7 @@ class CompaniesController < ApplicationController
def update
respond_to do |format|
if @company.update(company_params)
format.html { redirect_to company_url(@company), notice: "Company was successfully updated." }
format.html { redirect_to company_url(@company), notice: t('.company_updated') }
format.json { render :show, status: :ok, location: @company }
else
format.html { render :edit, status: :unprocessable_entity }
@@ -52,19 +50,30 @@ class CompaniesController < ApplicationController
@company.destroy!
respond_to do |format|
format.html { redirect_to companies_url, notice: "Company was successfully destroyed." }
format.html { redirect_to companies_url, notice: t('.company_destroyed') }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_company
@company = Company.find(params[:id])
end
# Only allow a list of trusted parameters through.
def company_params
params.require(:company).permit(:name, :id_number, :vat_number, :address_line_one, :address_line_two, :postal_code, :city, :entity, :country)
end
# Use callbacks to share common setup or constraints between actions.
def set_company
@company = Company.find(params[:id])
end
# Only allow a list of trusted parameters through.
def company_params
params.require(:company).permit(
:name,
:id_number,
:vat_number,
:address_line_one,
:address_line_two,
:postal_code,
:city,
:entity,
:country
)
end
end

View File

@@ -1,6 +1,6 @@
class CustomersController < ApplicationController
before_action :set_company
before_action :set_customer, only: %i[ show edit update destroy ]
before_action :set_customer, only: %i[show edit update destroy]
# GET /customers or /customers.json
def index
@@ -8,8 +8,7 @@ class CustomersController < ApplicationController
end
# GET /customers/1 or /customers/1.json
def show
end
def show; end
# GET /customers/new
def new
@@ -17,8 +16,7 @@ class CustomersController < ApplicationController
end
# GET /customers/1/edit
def edit
end
def edit; end
# POST /customers or /customers.json
def create
@@ -27,7 +25,7 @@ class CustomersController < ApplicationController
respond_to do |format|
if @customer.save
format.html { redirect_to customer_url(@customer), notice: "Customer was successfully created." }
format.html { redirect_to customer_url(@customer), notice: t('.customer_created') }
format.json { render :show, status: :created, location: @customer }
else
format.html { render :new, status: :unprocessable_entity }
@@ -40,7 +38,7 @@ class CustomersController < ApplicationController
def update
respond_to do |format|
if @customer.update(customer_params)
format.html { redirect_to customer_url(@customer), notice: "Customer was successfully updated." }
format.html { redirect_to customer_url(@customer), notice: t('.customer_updated') }
format.json { render :show, status: :ok, location: @customer }
else
format.html { render :edit, status: :unprocessable_entity }
@@ -54,19 +52,20 @@ class CustomersController < ApplicationController
@customer.destroy!
respond_to do |format|
format.html { redirect_to customers_url, notice: "Customer was successfully destroyed." }
format.html { redirect_to customers_url, notice: t('.customer_destroyed') }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_customer
@customer = Customer.find(params[:id])
end
# Only allow a list of trusted parameters through.
def customer_params
params.require(:customer).permit(:name, :phone, :notes, :email, :birthyear)
end
# Use callbacks to share common setup or constraints between actions.
def set_customer
@customer = Customer.find(params[:id])
end
# Only allow a list of trusted parameters through.
def customer_params
params.require(:customer).permit(:name, :phone, :notes, :email, :birthyear)
end
end

View File

@@ -1,17 +1,16 @@
class ReservationsController < ApplicationController
before_action :set_company
before_action :set_reservation, only: %i[ show edit update destroy ]
before_action :set_reservation, only: %i[show edit update destroy]
layout :determine_layout
# GET /reservations or /reservations.json
def index
@reservations = Reservation.all.includes(:team, :customer).where(company: @company)
@reservations = Reservation.includes(:team, :customer).where(company: @company)
@reservations = ActiveModelSerializers::SerializableResource.new(@reservations).as_json
end
# GET /reservations/1 or /reservations/1.json
def show
end
def show; end
# GET /reservations/new
def new
@@ -20,8 +19,7 @@ class ReservationsController < ApplicationController
end
# GET /reservations/1/edit
def edit
end
def edit; end
# POST /reservations or /reservations.json
def create
@@ -30,7 +28,7 @@ class ReservationsController < ApplicationController
respond_to do |format|
if @reservation.save
format.html { redirect_to reservation_url(@reservation), notice: "Reservation was successfully created." }
format.html { redirect_to reservation_url(@reservation), notice: t('.reservation_created') }
format.json { render :show, status: :created, location: @reservation }
else
format.html { render :new, status: :unprocessable_entity }
@@ -43,7 +41,7 @@ class ReservationsController < ApplicationController
def update
respond_to do |format|
if @reservation.update(reservation_params)
format.html { redirect_to reservation_url(@reservation), notice: "Reservation was successfully updated." }
format.html { redirect_to reservation_url(@reservation), notice: t('.reservation_updated') }
format.json { render :show, status: :ok, location: @reservation }
else
format.html { render :edit, status: :unprocessable_entity }
@@ -57,24 +55,25 @@ class ReservationsController < ApplicationController
@reservation.destroy!
respond_to do |format|
format.html { redirect_to reservations_url, notice: "Reservation was successfully destroyed." }
format.html { redirect_to reservations_url, notice: t('.reservation_destroyed') }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_reservation
@reservation = Reservation.find(params[:id])
end
# Only allow a list of trusted parameters through.
def reservation_params
params.require(:reservation).permit(:company_id, :customer_id, :team_id, :title, :description, :start_time, :end_time)
end
# Use callbacks to share common setup or constraints between actions.
def set_reservation
@reservation = Reservation.find(params[:id])
end
def determine_layout
action_name == 'index' ? 'calendar' : 'application'
end
# Only allow a list of trusted parameters through.
def reservation_params
params.require(:reservation).permit(:company_id, :customer_id, :team_id, :title, :description, :start_time,
:end_time)
end
def determine_layout
action_name == 'index' ? 'calendar' : 'application'
end
end

View File

@@ -1,5 +1,6 @@
class TeamsController < ApplicationController
before_action :set_team, only: %i[ show edit update destroy ]
before_action :set_company
before_action :set_team, only: %i[show edit update destroy]
# GET /teams or /teams.json
def index
@@ -7,8 +8,7 @@ class TeamsController < ApplicationController
end
# GET /teams/1 or /teams/1.json
def show
end
def show; end
# GET /teams/new
def new
@@ -16,17 +16,16 @@ class TeamsController < ApplicationController
end
# GET /teams/1/edit
def edit
end
def edit; end
# POST /teams or /teams.json
def create
@team = Team.new(team_params)
@team.company = Company.first
@team.company = @company
respond_to do |format|
if @team.save
format.html { redirect_to team_url(@team), notice: "Team was successfully created." }
format.html { redirect_to team_url(@team), notice: t('.team_created') }
format.json { render :show, status: :created, location: @team }
else
format.html { render :new, status: :unprocessable_entity }
@@ -37,10 +36,9 @@ class TeamsController < ApplicationController
# PATCH/PUT /teams/1 or /teams/1.json
def update
@team.company = Company.first
respond_to do |format|
if @team.update(team_params)
format.html { redirect_to team_url(@team), notice: "Team was successfully updated." }
format.html { redirect_to team_url(@team), notice: t('.team_updated') }
format.json { render :show, status: :ok, location: @team }
else
format.html { render :edit, status: :unprocessable_entity }
@@ -54,19 +52,20 @@ class TeamsController < ApplicationController
@team.destroy!
respond_to do |format|
format.html { redirect_to teams_url, notice: "Team was successfully destroyed." }
format.html { redirect_to teams_url, notice: t('.team_destroyed') }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_team
@team = Team.find(params[:id])
end
# Only allow a list of trusted parameters through.
def team_params
params.require(:team).permit(:name)
end
# Use callbacks to share common setup or constraints between actions.
def set_team
@team = Team.find(params[:id])
end
# Only allow a list of trusted parameters through.
def team_params
params.require(:team).permit(:name, :description)
end
end