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]) 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(@repository) else @repository = GithubRepository.new @repository_form_path = software_github_repository_index_path(@software.id) end end end def update @software = Software.find(params[:id]) if @software.update(software_params) redirect_to @software else render 'edit' end end def create @software = Software.new(software_params) if @software.save redirect_to @software else render 'new' end end def destroy @software = Software.find(params[:id]) @software.destroy redirect_to softwares_path end private def software_params params.require(:software).permit(:name, :website, :repository_type) end end