mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
rubocop fixing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class BeerclubsController < ApplicationController
|
||||
before_action :set_beerclub, only: %i[ show edit update destroy ]
|
||||
before_action :set_beerclub, only: %i[show edit update destroy]
|
||||
|
||||
# GET /beerclubs or /beerclubs.json
|
||||
def index
|
||||
@@ -58,13 +58,14 @@ class BeerclubsController < ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_beerclub
|
||||
@beerclub = Beerclub.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def beerclub_params
|
||||
params.require(:beerclub).permit(:name, :founded, :city)
|
||||
end
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_beerclub
|
||||
@beerclub = Beerclub.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def beerclub_params
|
||||
params.require(:beerclub).permit(:name, :founded, :city)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MembershipsController < ApplicationController
|
||||
before_action :set_membership, only: %i[ show edit update destroy ]
|
||||
before_action :set_membership, only: %i[show edit update destroy]
|
||||
|
||||
# GET /memberships or /memberships.json
|
||||
def index
|
||||
@@ -63,13 +63,14 @@ class MembershipsController < ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_membership
|
||||
@membership = Membership.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def membership_params
|
||||
params.require(:membership).permit(:user_id, :beerclub_id)
|
||||
end
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_membership
|
||||
@membership = Membership.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def membership_params
|
||||
params.require(:membership).permit(:user_id, :beerclub_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ class SessionsController < ApplicationController
|
||||
def create
|
||||
user = User.find_by username: params[:username]
|
||||
|
||||
if user && user.authenticate(params[:password])
|
||||
if user&.authenticate(params[:password])
|
||||
session[:user_id] = user.id if user
|
||||
redirect_to user_path user, notice: "Welcome back :)"
|
||||
else
|
||||
|
||||
@@ -17,9 +17,8 @@ class UsersController < ApplicationController
|
||||
|
||||
# GET /users/1/edit
|
||||
def edit
|
||||
if not @user == current_user
|
||||
# redirect_to user_path(@user), notice: "Not permitted to edit user"
|
||||
end
|
||||
return if @user == current_user
|
||||
# redirect_to user_path(@user), notice: "Not permitted to edit user"
|
||||
end
|
||||
|
||||
# POST /users or /users.json
|
||||
@@ -39,7 +38,6 @@ class UsersController < ApplicationController
|
||||
|
||||
# PATCH/PUT /users/1 or /users/1.json
|
||||
def update
|
||||
|
||||
respond_to do |format|
|
||||
if user_params[:username].nil? && @user == current_user && @user.update(user_params)
|
||||
format.html { redirect_to user_url(@user), notice: "User was successfully updated." }
|
||||
|
||||
@@ -8,9 +8,8 @@ class Beerclub < ApplicationRecord
|
||||
validate :creation_year_not_in_future
|
||||
|
||||
def creation_year_not_in_future
|
||||
if founded > Time.now.year
|
||||
errors.add :founded, "cannot be in the future"
|
||||
end
|
||||
end
|
||||
return unless founded > Time.now.year
|
||||
|
||||
errors.add :founded, "cannot be in the future"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,9 +10,9 @@ class Brewery < ApplicationRecord
|
||||
validate :creation_year_not_in_future
|
||||
|
||||
def creation_year_not_in_future
|
||||
if year > Time.now.year
|
||||
errors.add :year, "cannot be in the future"
|
||||
end
|
||||
return unless year > Time.now.year
|
||||
|
||||
errors.add :year, "cannot be in the future"
|
||||
end
|
||||
|
||||
def print_report
|
||||
|
||||
@@ -5,8 +5,8 @@ class Membership < ApplicationRecord
|
||||
validate :user_not_in_club
|
||||
|
||||
def user_not_in_club
|
||||
if not Membership.find_by(user_id:user_id, beerclub_id:beerclub_id).nil?
|
||||
errors.add :user_id, "is already in the beerclub"
|
||||
end
|
||||
return if Membership.find_by(user_id:, beerclub_id:).nil?
|
||||
|
||||
errors.add :user_id, "is already in the beerclub"
|
||||
end
|
||||
end
|
||||
|
||||
+5
-5
@@ -5,17 +5,17 @@ class User < ApplicationRecord
|
||||
|
||||
validates :username, uniqueness: true, length: { minimum: 3, maximum: 30 }
|
||||
validates :password, length: { minimum: 3 }
|
||||
validate :has_proper_characters_in_password
|
||||
validate :proper_characters_in_password?
|
||||
|
||||
has_many :ratings, dependent: :destroy
|
||||
has_many :beers, through: :ratings
|
||||
has_many :memberships, dependent: :destroy
|
||||
has_many :beer_clubs, through: :memberships
|
||||
|
||||
def has_proper_characters_in_password
|
||||
def proper_characters_in_password?
|
||||
regex = "(?=.*[[:upper:]])(?=.*[0-9])"
|
||||
if not password&.match(regex)
|
||||
errors.add :password, "doesn't contain uppercase letter and a number"
|
||||
end
|
||||
return false if password&.match(regex)
|
||||
|
||||
errors.add :password, "doesn't contain uppercase letter and a number"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user