class SoftwaresController < ApplicationController before_action :find_software, only: %i[show edit update destroy] def index @softwares = Software.all end def new @software = Software.new end def show; end def edit 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 end def update if @software.update(software_params) redirect_to edit_software_path(@software) else render 'edit' end end def create @software = Software.new(software_params) if @software.save redirect_to edit_software_path(@software) else render 'new' end end def destroy @software.destroy redirect_to softwares_path end private def software_params params.require(:software).permit(:name, :website, :repository_type) end def find_software @software = Software.find(params[:id]) end end