Skip to content

Commit f698b0f

Browse files
committed
Clarify even further where to put use_new_acts_as
1 parent f363f47 commit f698b0f

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

docs/_advanced/upgrading-to-1.7.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,19 @@ The chat UI works with your existing Chat and Message models and includes:
191191

192192
## Troubleshooting
193193

194-
### "undefined local variable or method 'acts_as_model'" error during migration
194+
### Config must be set before models load
195195

196-
If you get this error when running `rails db:migrate`, add the configuration to `config/application.rb` **before** your Application class:
196+
If you're setting `use_new_acts_as = true` in an initializer (like `config/initializers/ruby_llm.rb`), it won't work. Rails loads models before initializers run, causing various issues:
197+
198+
**Symptoms:**
199+
- Legacy `acts_as` module gets included even though you set `use_new_acts_as = true`
200+
- `undefined local variable or method 'acts_as_model'` error during migration
201+
- Errors referencing `lib/ruby_llm/active_record/acts_as_legacy.rb` in backtraces
202+
- Works in development/staging but fails in production
203+
204+
**Solution:**
205+
206+
Add the configuration to `config/application.rb` **before** your Application class:
197207

198208
```ruby
199209
# config/application.rb
@@ -212,7 +222,12 @@ module YourApp
212222
end
213223
```
214224

215-
This ensures RubyLLM is configured before ActiveRecord loads your models.
225+
This ensures RubyLLM is configured before ActiveRecord loads your models. Other configuration options (API keys, timeouts, etc.) can still go in your initializer.
226+
227+
> This limitation exists because both legacy and new `acts_as` APIs need to coexist during the 1.x series. It will be resolved in RubyLLM 2.0 when the legacy API is removed.
228+
{: .note }
229+
230+
See the [Configuration guide]({% link _getting_started/configuration.md %}#initializer-load-timing-issue-with-use_new_acts_as) for more details.
216231

217232
## New Applications
218233

docs/_getting_started/configuration.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,36 @@ RubyLLM.configure do |config|
324324
end
325325
```
326326

327+
### Initializer Load Timing Issue with `use_new_acts_as`
328+
329+
**Important**: If you're using `use_new_acts_as = true` (from upgrading to 1.7+), you **cannot** set it in an initializer. Rails loads models before initializers run, so the legacy `acts_as` module will already be included by the time your initializer executes.
330+
331+
Instead, configure it in `config/application.rb` **before** the `Application` class:
332+
333+
```ruby
334+
# config/application.rb
335+
require_relative "boot"
336+
require "rails/all"
337+
338+
# Configure RubyLLM before Rails::Application is inherited
339+
RubyLLM.configure do |config|
340+
config.use_new_acts_as = true
341+
end
342+
343+
module YourApp
344+
class Application < Rails::Application
345+
# ...
346+
end
347+
end
348+
```
349+
350+
This ensures RubyLLM is configured before ActiveRecord loads your models. Other configuration options (API keys, timeouts, etc.) can still go in your initializer.
351+
352+
> This limitation exists because both legacy and new `acts_as` APIs need to coexist during the 1.x series. It will be resolved in RubyLLM 2.0 when the legacy API is removed.
353+
{: .note }
354+
355+
See the [Upgrading to 1.7 guide]({% link _advanced/upgrading-to-1.7.md %}#troubleshooting) for more details.
356+
327357
## Configuration Reference
328358

329359
Here's a complete reference of all configuration options:

0 commit comments

Comments
 (0)