Initializer fails when used in global_bc_items.yml.erb

we have OOD v4.2.3 and our my_accounts initializer works when put in form.yml.erb like the following

account:
  widget: 'select'
  options:
  <%  OodSupport::User.new.my_accounts.each do |line| %>
  - "<%= line %>"
  <%- end %>

but fails when we move this to our global_bc_items.yml.erb as global_account and use - global_account in form.yml.erb. The other global_ form items in global_bc_items.yml.erb that don’t use an initializer are working correctly

This has to do with the boot order. The configuration is loaded first, before rails or any other gem dependency, so ood_support isn’t available (or your extended class from an initializer) at this time.

You can extend a class still in pure Ruby, but I’d suggest sub classing as it’s a little more straight forward. So you’d have some file that’s the subclass (note you don’t want rails here):

# /some/file.rb

require 'ood_support'

class MyUser < OodSupport::User
  def my_accounts
    # your custom implementation here
  end
end

Then you can require /some/file.rb in your ERB config file directly and it should load.

thanks for the help. I’ve tried the following but it didn’t work, but worked after removing a different unrelated failing form item

#/etc/ood/config/init4globals.rb

require 'ood_support'

class MyUser < OodSupport::User
  def my_accounts
      @my_accounts ||= begin
        # myproject is a custom script returning a list of project numbers one per line
        cmd = "/sw/local/bin/myproject"
        o, e, s = Open3.capture3(cmd)
        o.chomp.split
      end
  end
end
# /etc/ood/config/ondemand.d/global_bc_items.yml.erb

<% require '/etc/ood/config/init4globals.rb' %>

  global_my_accounts:
    widget: 'select'
    options:
       <%  MyUser.new.my_accounts.each do |line| %>
       - "<%= line %>"
       <%- end %>
#form.yml.erb

 - global_my_accounts

There’s likely some error message in /var/log/ondemand-nginx/$USER/error.log. Can you share what it is?

the error.log shows that a different form item was causing a read/parse error for global_bc_items.yml.erb
I removed the other failing item without changing the above code and it works.
I added one comment to the code above describing our custom myproject script output
Thanks,