2018-07-22 15:44:29 +00:00
|
|
|
class SoftwaresController < ApplicationController
|
|
|
|
def index
|
|
|
|
@softwares = Software.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@software = Software.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@software = Software.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@software = Software.find(params[:id])
|
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
|
|
|
|
@software = Software.find(params[:id])
|
|
|
|
|
|
|
|
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 = Software.find(params[:id])
|
|
|
|
@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
|
|
|
|
end
|