chore: use before_action in softwares controller
This commit is contained in:
parent
50266be909
commit
a36060eb84
1 changed files with 7 additions and 8 deletions
|
@ -1,4 +1,6 @@
|
|||
class SoftwaresController < ApplicationController
|
||||
before_action :find_software, only: %i[show edit update destroy]
|
||||
|
||||
def index
|
||||
@softwares = Software.all
|
||||
end
|
||||
|
@ -7,13 +9,9 @@ class SoftwaresController < ApplicationController
|
|||
@software = Software.new
|
||||
end
|
||||
|
||||
def show
|
||||
@software = Software.find(params[:id])
|
||||
end
|
||||
def show; end
|
||||
|
||||
def edit
|
||||
@software = Software.find(params[:id])
|
||||
|
||||
case @software.repository_type
|
||||
when 'Github'
|
||||
if GithubRepository.exists?(software_id: @software)
|
||||
|
@ -27,8 +25,6 @@ class SoftwaresController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
@software = Software.find(params[:id])
|
||||
|
||||
if @software.update(software_params)
|
||||
redirect_to edit_software_path(@software)
|
||||
else
|
||||
|
@ -47,7 +43,6 @@ class SoftwaresController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
@software = Software.find(params[:id])
|
||||
@software.destroy
|
||||
|
||||
redirect_to softwares_path
|
||||
|
@ -58,4 +53,8 @@ class SoftwaresController < ApplicationController
|
|||
def software_params
|
||||
params.require(:software).permit(:name, :website, :repository_type)
|
||||
end
|
||||
|
||||
def find_software
|
||||
@software = Software.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue