# Initializer fails when used in global\_bc\_items.yml.erb

**URL:** <https://discourse.openondemand.org/t/initializer-fails-when-used-in-global-bc-items-yml-erb/4945>\
**Category:** Get Help\
**Created:** [August 10, 2026, 10:56pm UTC](https://discourse.openondemand.org/t/initializer-fails-when-used-in-global-bc-items-yml-erb/4945 "2026-08-10T22:56:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmdickens](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/cmdickens/32/1285_2.png) [@cmdickens](https://discourse.openondemand.org/u/cmdickens)\
**Post date:** [August 10, 2026, 10:56pm UTC](https://discourse.openondemand.org/t/initializer-fails-when-used-in-global-bc-items-yml-erb/4945/1 "2026-08-10T22:56:56Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [August 12, 2026, 1:52pm UTC](https://discourse.openondemand.org/t/initializer-fails-when-used-in-global-bc-items-yml-erb/4945/2 "2026-08-12T13:52:25Z")

</div>

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):

```auto
# /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.

---

<div class="post-metadata">

**Author:** ![cmdickens](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/cmdickens/32/1285_2.png) [@cmdickens](https://discourse.openondemand.org/u/cmdickens)\
**Post date:** [August 14, 2026, 5:03pm UTC](https://discourse.openondemand.org/t/initializer-fails-when-used-in-global-bc-items-yml-erb/4945/3 "2026-08-14T17:03:26Z")

</div>

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

```auto
#/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

```

```auto
# /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 %>

```

```auto
#form.yml.erb

 - global_my_accounts

```

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [August 14, 2026, 5:10pm UTC](https://discourse.openondemand.org/t/initializer-fails-when-used-in-global-bc-items-yml-erb/4945/4 "2026-08-14T17:10:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmdickens](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/cmdickens/32/1285_2.png) [@cmdickens](https://discourse.openondemand.org/u/cmdickens)\
**Post date:** [August 14, 2026, 6:45pm UTC](https://discourse.openondemand.org/t/initializer-fails-when-used-in-global-bc-items-yml-erb/4945/5 "2026-08-14T18:45:27Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)\
**Post date:** [August 16, 2026, 6:45pm UTC](https://discourse.openondemand.org/t/initializer-fails-when-used-in-global-bc-items-yml-erb/4945/6 "2026-08-16T18:45:43Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
