Separate controllers in files

42 views
Skip to first unread message

Jorge Fuertes Alfranca

unread,
Jul 27, 2013, 5:23:29 PM7/27/13
to scor...@googlegroups.com
Hi all.

I'm giving a try to Scorched, I really like his KISS design.
But i'm barely new to Ruby, and there are a bunch of basic things too hard for me. So I ask forgiveness before my question.

I want to put separate controllers at files, and i'm requiring it from main app file, this works fine if this separate controllers comes from and "< Scorched::Controller", but it don't works when I try to make a "< ControllerA" heritage:

NameError: uninitialized constant ControllerA.

This error comes from the ControllerB file, required from main file where ControllerA resides.

What i'm doing wrong?

Thanks!

Tom Wardrop

unread,
Jul 27, 2013, 6:51:15 PM7/27/13
to scor...@googlegroups.com
If ControllerA and ControllerB are in separate files, ensure you're loading ControllerA first. Scorched doesn't include any auto-loading functionality, so it's up to you, the user, to find a loading strategy that suits your application. 

For your own sake, here's essentially what you should have done (in the same, or separate files):

ControllerA < Scorched::Controller

end


ControllerB < ControllerA

end

Cheers,
Tom

Jorge Fuertes Alfranca

unread,
Jul 28, 2013, 10:34:21 AM7/28/13
to scor...@googlegroups.com
I have find my problem...

Same code works with rackup but crashes with shotgun. Very strange.

It's attached to this mail if you want to see it.

Thanks!
scorchedtest.tar.gz

Tom Wardrop

unread,
Aug 5, 2013, 7:01:00 PM8/5/13
to scor...@googlegroups.com
It's an issue with Shotgun. It does a bit of funky stuff with the context in which it executes the rackup file which can cause issues with namespaces, etc. In your example, `MyApp` is defined under `Shotgun::Loader::MyApp`, hence why the code in your other files which doesn't live under the `Shotgun::Loader` module can't find `MyApp`. If you move your application code from `app.ru` to another file, like `app.rb`, it'll work. For example, here's what your rackup file should look like, with everything else moved to `app.rb`:

require 'scorched'
require 'require_all'
require 'json'
require './app'

run MyApp

Cheers,
Tom
Reply all
Reply to author
Forward
0 new messages