diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 490072b4bd..5816730466 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -26,13 +26,13 @@ def show redirect_to projects_path return end - + @project = projects.first @ontologies_used = [] onts_used = @project.ontologyUsed onts_used.each do |ont_used| ont = LinkedData::Client::Models::Ontology.find(ont_used) - unless ont.nil? + unless ont.nil? || ont.errors @ontologies_used << Hash["name", ont.name, "acronym", ont.acronym] end end @@ -62,7 +62,7 @@ def edit @project = projects.first @user_select_list = LinkedData::Client::Models::User.all.map {|u| [u.username, u.id]} @user_select_list.sort! {|a,b| a[1].downcase <=> b[1].downcase} - @usedOntologies = @project.ontologyUsed || [] + @usedOntologies = @project.ontologyUsed&.map{|o| o.split('/').last} @ontologies = LinkedData::Client::Models::Ontology.all end @@ -76,7 +76,7 @@ def create @project = LinkedData::Client::Models::Project.new(values: project_params) @project_saved = @project.save - + # Project successfully created. if response_success?(@project_saved) flash[:notice] = t('projects.project_successfully_created') @@ -160,10 +160,10 @@ def destroy def project_params p = params.require(:project).permit(:name, :acronym, :institution, :contacts, { creator:[] }, :homePage, :description, { ontologyUsed:[] }) - + p[:creator]&.reject!(&:blank?) - p[:ontologyUsed]&.reject!(&:blank?) - p.to_h + p[:ontologyUsed] ||= [] + p = p.to_h end def flash_error(msg) diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index cd3eea4235..55bdb61edc 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -53,5 +53,5 @@ %div#ontology_picker_project{style: "padding-top: 2em;"} - selected_ontologies = @project.ontologyUsed && @project.ontologyUsed.map {|id| id.split('/').last } || [] - locals = { sel_text: t('projects.form.select_ontologies'), selected_ontologies: selected_ontologies, form_object: :project, form_attribute: "ontologyUsed" } - = ontologies_selector(id:'projects_page_ontologies_selector' ,name: 'ontologies') + = ontologies_selector(id:'projects_page_ontologies_selector' ,name: 'project[ontologyUsed][]', selected: @usedOntologies)