2018-07-22 15:44:29 +00:00
|
|
|
class SoftwaresController < ApplicationController
|
2018-08-04 05:50:21 +00:00
|
|
|
before_action :find_software, only: %i[show edit update destroy]
|
|
|
|
|
2018-07-22 15:44:29 +00:00
|
|
|
def index
|
|
|
|
@softwares = Software.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@software = Software.new
|
|
|
|
end
|
|
|
|
|
2018-08-04 05:50:21 +00:00
|
|
|
def show; end
|
2018-07-22 15:44:29 +00:00
|
|
|
|
|
|
|
def edit
|
2018-07-29 19:06:32 +00:00
|
|
|
case @software.repository_type
|
|
|
|
when 'Github'
|
|
|
|
if GithubRepository.exists?(software_id: @software)
|
|
|
|
@repository = GithubRepository.where(software_id: @software.id).take
|
|
|
|
@repository_form_path = software_github_repository_path(software_id: @software.id, id: @repository.id)
|
|
|
|
else
|
|
|
|
@repository = GithubRepository.new
|
|
|
|
@repository_form_path = software_github_repository_index_path(@software.id)
|
|
|
|
end
|
|
|
|
end
|
2018-07-22 15:44:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @software.update(software_params)
|
2018-07-30 19:51:38 +00:00
|
|
|
redirect_to edit_software_path(@software)
|
2018-07-22 15:44:29 +00:00
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@software = Software.new(software_params)
|
|
|
|
|
|
|
|
if @software.save
|
2018-07-30 19:51:38 +00:00
|
|
|
redirect_to edit_software_path(@software)
|
2018-07-22 15:44:29 +00:00
|
|
|
else
|
|
|
|
render 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@software.destroy
|
|
|
|
|
|
|
|
redirect_to softwares_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def software_params
|
2018-07-29 19:06:32 +00:00
|
|
|
params.require(:software).permit(:name, :website, :repository_type)
|
2018-07-22 15:44:29 +00:00
|
|
|
end
|
2018-08-04 05:50:21 +00:00
|
|
|
|
|
|
|
def find_software
|
|
|
|
@software = Software.find(params[:id])
|
|
|
|
end
|
2018-07-22 15:44:29 +00:00
|
|
|
end
|