'Unable to populate the drop down list (Rails)

I am using Rails MVC project. My models are as follows

TransferRequest.rb

class TransferRequest < ApplicationRecord
  belongs_to :user
  belongs_to :cohort, optional:true
  has_many :biomaterial_items, dependent: :destroy
  has_many :activities, dependent: :destroy
  has_many :attachments, dependent: :destroy
  has_many :questions, dependent: :destroy
  belongs_to :principal_applicant, class_name: "Contact", optional: :draft?
  belongs_to :shipment_address, class_name: "Contact", optional: true
  belongs_to :billing_address, class_name: "Contact", optional: true
 enum biobank: {
    "PopGen" => 0,
    "Healthcare Embedded Biobanking" => 1,
    "BMB-CCC" => 2,
    "UKSH Clinic Consent" => 3,
    "BMB-GYN" => 4
  }

Cohort.rb

class Cohort < ApplicationRecord
  has_many :transfer_requests
  belongs_to :biobank
  def to_s
    disease_name
  end
end

Transfer_requests_controller.rb

 def create
    @transfer_request = TransferRequest.new(transfer_request_params)
    @transfer_request.application_date=Date.today
    @transfer_request.status = "draft"
    @transfer_request.user = @current_user

    if @transfer_request.save
      redirect_to edit_transfer_request_path(@transfer_request)
    else
      render :new
    end
  end

My view is as follows _form.html.haml

%h3 Basic
.form-group{class: ("has-error" if @transfer_request.errors.has_key?("Access requested to"))}
  = f.label "Access requested to", class: "control-label"
  %br
  Biomaterial #{f.check_box :access_biomaterial}
  Data #{f.check_box :access_data}
  = f.error "Access requested to"
= f.input :project_title
= javascript_include_tag "application", "data-turbolinks-track" => true
= f.input :biobank, collection: TransferRequest.biobanks.keys, prompt: 'Select biobank', id: 'biobank', :input_html => {:onclick => "getBiobank()", :class => "stext"} 
= f.association :cohort, collection: Cohort.all, prompt: 'Select Cohort', id: 'cohort'
-#f.collection_select(nil, :biobank_id, @biobanks, :id, :name, {:prompt => "Select biobank"}, {:id => 'biobanks_select'})
-#f.collection_select(nil, :cohort_id, @cohorts, :id, :name, {:prompt => "Select cohort"}, {:id => 'cohorts_select'})

I am unable to populate the select tag,cohort, in the views from a runner file as shown below

read_csv.rb

require 'csv'
csv_text = File.read(Rails.root.join('lib', 'seeds', 'popgen_zwei_dbo_disease.csv'))
csv = CSV.parse(csv_text, headers: true, :encoding => 'ISO-8859-1', :skip_lines=> /-/)
csv.each do |row|
  t = Cohort.new
  t.disease_code_id = row[0]
  t.disease_name = row[1]
  t.save
end

Any hints would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source