kaiho/app/controllers/softwares_controller.rb

61 lines
1.3 KiB
Ruby
Raw Normal View History

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