Skip to content

Commit

Permalink
fix non standart style in model
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSipayung committed Feb 1, 2024
1 parent 4eec919 commit 6c948a9
Show file tree
Hide file tree
Showing 15 changed files with 498 additions and 465 deletions.
9 changes: 5 additions & 4 deletions app/controllers/microposts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class MicropostsController < ApplicationController
# only login user could create and destroy it's post
before_action :logged_in_user, only: %i[create destroy]
before_action :correct_user, only: :destroy
# the present of current_user is to tell that create it by
# who already logged in and to make the current user post
# using build, since we work with collection, return new object of collection
# add image to newly created micropost object

def create
# the present of current_user is to tell that create it by
# who already logged in and to make the current user post
# using build, since we work with collection, return new object of collection
@micropost = current_user.microposts.build(micropost_params)
# add image to newly created micropost object
@micropost.image.attach(params[:micropost][:image])
if @micropost.save # save the post's current user
flash[:success] = 'Micropost created!'
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/password_resets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PasswordResetsController < ApplicationController
# Because confirmation of the existence of a valid @user
# is needed in both the update and edit actions
before_action :logged_in_user, except: %i[update new create edit]
before_action :get_user, only: %i[edit update]
before_action :find_user, only: %i[edit update]
before_action :valid_user, only: %i[edit update]
# make sure the reset password is not expired
before_action :check_expiration, only: %i[edit update]
Expand Down Expand Up @@ -42,7 +42,7 @@ def edit; end
private

# only valid user can get request edit password
def get_user
def find_user
@user = User.find_by(email: params[:email])
end

Expand Down
4 changes: 0 additions & 4 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ def create
if user&.authenticate(params[:session][:password])
if user.activated
log_in user # log the user in (session)
# remember user only if the user clicked remember
params[:session][:remember_me] == '1' ? remember(user) : forget(user)
# remember(user)
redirect_back_or user # automatically convert to the route user_url(user)
else
message = 'Account not activated'
message += 'Check your email for activation link'
flash[:warning] = message
redirect_to root_url
end
else
# create an error message
flash.now[:danger] = 'Invalid email/password combination'
render 'new'
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

# static pages, serve static content
class StaticPagesController < ApplicationController
skip_before_action :logged_in_user, only: %i[home help about contact]
def home
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/utbk_scores_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def show; end

def utbk_score_params
params.require(:utbk_score).permit(:no_peserta, :tanggal_ujian,
:jumlah_nilai_semester_6,
:jumlah_pelajaran_semester_6,
:jumlah_nilai_semester6,
:jumlah_pelajaran_semester6,
:nilai_penalaran_umum,
:nilai_pengetahuan_kuantitatif,
:nilai_kemampuan_memahami_bacaan_dan_menulis,
Expand Down
23 changes: 17 additions & 6 deletions app/models/pmdk_each_score_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
# model pmdk_each_score_information : handle pmdk_each_score_information
class PmdkEachScoreInformation < ApplicationRecord
belongs_to :user
validates :matematika_semester1, :matematika_semester2, :matematika_semester3, :matematika_semester4,
:matematika5, :kimia1, :kimia2, :kimia3, :kimia4,
:kimia5, :fisika1, :fisika2, :fisika3, :fisika4,
:fisika5, :inggris1, :inggris2, :inggris3,
:inggris4, :inggris5, presence: true,
numericality: { only_integer: false, greater_than_or_equal_to: 2, less_than_or_equal_to: 100 }
validates :matematika_semester1,
:matematika_semester2,
:matematika_semester3,
:matematika_semester4,
:matematika5,
:kimia1,
:kimia2,
:kimia3,
:kimia4,
:kimia5,
:fisika1, :fisika2,
:fisika3, :fisika4,
:fisika5, :inggris1,
:inggris2, :inggris3,
:inggris4, :inggris5,
presence: true,
numericality: { only_integer: false, greater_than_or_equal_to: 2, less_than_or_equal_to: 100 }
has_one_attached :sertifikat
validates :sertifikat, content_type: [:pdf], size: { less_than: 1.megabytes }
end
16 changes: 12 additions & 4 deletions app/models/pmdk_total_score_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
# model PmdkTotalScoreInformation : handle pmdk_total_score_information
class PmdkTotalScoreInformation < ApplicationRecord
belongs_to :user
validates :jumlah_nilai_semester1, :jumlah_nilai_semester2, :jumlah_nilai_semester3,
:jumlah_nilai_semester4, :jumlah_nilai_semester5, presence: true,
validates :jumlah_nilai_semester1,
:jumlah_nilai_semester2,
:jumlah_nilai_semester3,
:jumlah_nilai_semester4,
:jumlah_nilai_semester5,
presence: true,
numericality: { only_integer: false, greater_than_or_equal_to: 2, less_than_or_equal_to: 3000 }
validates :jumlah_pelajaran_semester1, :jumlah_pelajaran_semester2, :jumlah_pelajaran_semester3,
:jumlah_pelajaran_semester4, :jumlah_pelajaran_semester5, presence: true,
validates :jumlah_pelajaran_semester1,
:jumlah_pelajaran_semester2,
:jumlah_pelajaran_semester3,
:jumlah_pelajaran_semester4,
:jumlah_pelajaran_semester5,
presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 2, less_than_or_equal_to: 30 }
has_one_attached :surat_rekomendasi
validates :surat_rekomendasi, content_type: [:pdf], size: { less_than: 1.megabytes }
Expand Down
4 changes: 2 additions & 2 deletions app/models/utbk_score.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class UtbkScore < ApplicationRecord
:nilai_kemampuan_memahami_bacaan_dan_menulis,
presence: true, numericality: { only_integer: false,
greater_than_or_equal_to: 5, less_than_or_equal_to: 2000 }
validates :jumlah_nilai_semester_6,
validates :jumlah_nilai_semester6,
presence: true, numericality: { only_integer: false,
greater_than_or_equal_to: 2, less_than_or_equal_to: 2000 }
validates :jumlah_pelajaran_semester_6,
validates :jumlah_pelajaran_semester6,
presence: true, numericality: { only_integer: true,
greater_than_or_equal_to: 2, less_than_or_equal_to: 100 }
has_one_attached :sertifikat_utbk # active storange api
Expand Down
8 changes: 4 additions & 4 deletions app/views/shared/_utbk_score_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
placeholder: 'Nilai Pengetahuan Kuantitatif' %>
<%= f.text_field :nilai_kemampuan_memahami_bacaan_dan_menulis, class: 'form-control',
placeholder: 'Nilai Kemampuan Memahami Bacaan & Menulis' %>
<%= f.text_field :jumlah_nilai_semester_6, class: 'form-control',
placeholder: 'Jumlah Nilai Semester 6' %>
<%= f.number_field :jumlah_pelajaran_semester_6, class: 'form-control',
placeholder: 'Jumlah Pelajaran Semester 6' %>
<%= f.text_field :jumlah_nilai_semester6, class: 'form-control',
placeholder: 'Jumlah Nilai Semester 6' %>
<%= f.number_field :jumlah_pelajaran_semester6, class: 'form-control',
placeholder: 'Jumlah Pelajaran Semester 6' %>
<span class="image">
<%= f.file_field :sertifikat_utbk, accept: "application/pdf" %>
</span>
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20240201000155_rename_column_total_score.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RenameColumnTotalScore < ActiveRecord::Migration[7.1]
def change
rename_column :pmdk_total_score_informations, :jumlah_nilai_semester_1,
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20240201001601_rename_column_usm.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RenameColumnUsm < ActiveRecord::Migration[7.1]
def change
rename_column :usm_school_informations, :jumlah_nilai_semester_5,
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20240201014932_rename_column_utbk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class RenameColumnUtbk < ActiveRecord::Migration[7.1]
def change
rename_column :utbk_scores, :jumlah_pelajaran_semester_6,
:jumlah_pelajaran_semester6
rename_column :utbk_scores, :jumlah_nilai_semester_6,
:jumlah_nilai_semester6
end
end
Loading

0 comments on commit 6c948a9

Please sign in to comment.