Hi I'm currently working on making ActiveRBAC (https:// activerbac.turingstudio.com) into an engine. However, there seems to be a problem with Controllers and Namespaces. I want my controller to be in the "ActiveRBAC" namespace since ActiveRBAC contains controllers with more or less common names such as "UserController". A quick look at the mail archive shows me that there are known problems. Could someone give me an abstract of the problems? How much work would it be to add namespace support for controllers to rails- engines? I'd be willing to give it a try, then. Regards Manuel Holtgrewe
on 2006-02-03 15:05
on 2006-02-03 15:18
The problems stem from the strange way that Rails has been require-ing controllers within modules. Old (1.0.0, 1.0.1) versions of the Engines plugin would strip everything bar the filename out of the require path in order to quickly do the code mixing, but that also removes module information (since ActiveRBAC::UserController would be required as 'active_rbac/user_controller'). The biggest problem is that different installations of Rails seem to use different paths when require-ing controllers. That's what I've spent the last 3 point-releases chasing. The current version of the Engines plugin (1.0.6) *should* fix all of these problems - if you find you're having problems then post here (preferrable with traces from the engine logger; see Engines.log for details about how to turn it on) and we'll work through it. - james On 2/3/06, Manuel Holtgrewe <purestorm@ggnore.net> wrote: > A quick look at the mail archive shows me that there are known > http://lists.rails-engines.org/listinfo.cgi/engine... > -- * J * ~
on 2006-02-03 17:52
Hi > The current version of the Engines plugin (1.0.6) *should* fix all of > these problems - if you find you're having problems then post here > (preferrable with traces from the engine logger; see Engines.log for > details about how to turn it on) and we'll work through it. I did not find any documentation about how to turn on traces, the only thing I found was a call to Engine.create_logger which I added to my environment.rb. The source of the engine can be found here: http://www.6URL.com/0EJE Here is the trace: ==8<========================= manuel@coxorange.local 17:45:58 rbac_demo $> ./script/server => Booting WEBrick... Starting engine 'active_rbac' from '/Users/manuel/Development/Rails/ arbac.ts.com/rbac_demo/trunk/rbac_demo/vendor/plugins/active_rbac' adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/views/user to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/views/static_permission to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/views/shared to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/views/role to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/views/registration_mailer to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/views/registration to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/views/login to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/views/group to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/views to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/model to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/helpers to the load path adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ rbac_demo/vendor/plugins/active_rbac/app/controllers to the load path No init_engines.rb file found for engine 'active_rbac'... Attempting to copy public engine files from './vendor/plugins/ active_rbac/public' => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2006-02-03 17:46:02] INFO WEBrick 1.3.1 [2006-02-03 17:46:02] INFO ruby 1.8.2 (2004-12-25) [powerpc- darwin8.2.0] [2006-02-03 17:46:02] INFO WEBrick::HTTPServer#start: pid=6766 port=3000 Engines' require_or_load for './app/controllers/application.rb' finally loading from application: './app/controllers/application.rb' Engines' require_or_load for 'application_helper' requiring helper file 'application_helper' --> rewrote to 'application_helper' --> checking 'active_rbac' for ./vendor/plugins/active_rbac/app/ helpers/application_helper.rb finally loading from application: 'application_helper.rb' Engines' require_or_load for 'application_api' finally loading from application: 'application_api.rb' Engines' require_or_load for 'user' finally loading from application: 'user.rb' Engines' require_or_load for 'group' finally loading from application: 'group.rb' Engines' require_or_load for 'role' finally loading from application: 'role.rb' Engines' require_or_load for 'static_permission' finally loading from application: 'static_permission.rb' Engines' require_or_load for 'user_registration' finally loading from application: 'user_registration.rb' Engines' require_or_load for './vendor/plugins/active_rbac/app/ controllers/user_controller.rb' requiring controller file './vendor/plugins/active_rbac/app/ controllers/user_controller.rb' --> rewrote to 'user_controller.rb' --> checking 'active_rbac' for ./vendor/plugins/active_rbac/app/ controllers/user_controller.rb --> found, loading from engine 'active_rbac' Engines' require_or_load for 'vendor/plugins/active_rbac/app/helpers/ rbac_helper' requiring helper file 'vendor/plugins/active_rbac/app/helpers/ rbac_helper' --> rewrote to 'rbac_helper' --> checking 'active_rbac' for ./vendor/plugins/active_rbac/app/ helpers/rbac_helper.rb --> found, loading from engine 'active_rbac' finally loading from application: 'vendor/plugins/active_rbac/app/ helpers/rbac_helper.rb' Engines' require_or_load for 'active_rbac' finally loading from application: 'active_rbac.rb' 127.0.0.1 - - [03/Feb/2006:17:46:15 CET] "GET /user HTTP/1.1" 500 10329 - -> /user ==8<========================= Regards Manuel Holtgrewe
on 2006-02-03 17:58
You need to remembered to put your modularized controllers into subfolders, i.e. "class ActiveRbac::UserController < .... " would go into ./vendor/plugins/active_rbac/app/controllers/active_rbac/user_controller.rb.... - james On 2/3/06, Manuel Holtgrewe <purestorm@ggnore.net> wrote: > > rbac_demo/vendor/plugins/active_rbac/app/views/user to the load path > adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ > adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ > darwin8.2.0] > Engines' require_or_load for 'application_api' > finally loading from application: 'user_registration.rb' > requiring helper file 'vendor/plugins/active_rbac/app/helpers/ > - -> /user > http://lists.rails-engines.org/listinfo.cgi/engine... > -- * J * ~
on 2006-02-03 17:58
"need to remember" - d'oh. Bad typing today. On 2/3/06, James Adam <james.adam@gmail.com> wrote: > > > these problems - if you find you're having problems then post here > > > > adding /Users/manuel/Development/Rails/arbac.ts.com/rbac_demo/trunk/ > > rbac_demo/vendor/plugins/active_rbac/app/views/login to the load path > > No init_engines.rb file found for engine 'active_rbac'... > > finally loading from application: './app/controllers/application.rb' > > Engines' require_or_load for 'group' > > controllers/user_controller.rb' > > helpers/rbac_helper.rb > > > -- > * J * > ~ > -- * J * ~
on 2006-02-03 18:37
Am 03.02.2006 um 17:55 schrieb James Adam: > You need to remembered to put your modularized controllers into > subfolders, i.e. "class ActiveRbac::UserController < .... " would go > into ./vendor/plugins/active_rbac/app/controllers/active_rbac/ > user_controller.rb.... OK. IMO this is not exactly elegant. Shouldn't all classes be prefixed by the engine's name automatically? Regards Manuel Holtgrewe
on 2006-02-03 18:58
Do you mean that every class in the engine 'MyEngine' should be put into the module MyEngine? i.e. class User < ActiveRecord::Base automatically becomes class MyEngine::User < ActiveRecord::Base ? While something like this is superficially appealing, it's actually way more complicated to implement (even Rails doesn't support this yet) and IMHO adding 'more magic' at this point isn't a brilliant idea. When you're writing a regular Rails application, any controllers that are within modules have to reside in a sub-folder of the app/controllers directory - there's no way around that. This is mirrored directly in the way that Engines work - if you want your controllers to be in modules, you have to put them in subfolders; the fact they're in an engine isn't important. The way that Rails controllers exist within Modules is pretty much a hack in Rails itself right now. The module is half there for reloading purposes, and half for routing (i.e. to let you put controllers under subdirectories on your site). So to answer your point - it's no more or no less elegant than if you were developing the controllers in your application directly. Only time will tell how things might be improved. - james On 2/3/06, Manuel Holtgrewe <purestorm@ggnore.net> wrote: > IMO this is not exactly elegant. Shouldn't all classes be prefixed by > http://lists.rails-engines.org/listinfo.cgi/engine... > -- * J * ~
on 2006-02-04 12:44
Am 03.02.2006 um 18:55 schrieb James Adam: > Do you mean that every class in the engine 'MyEngine' should be put > into the module MyEngine? > > i.e. class User < ActiveRecord::Base automatically becomes class > MyEngine::User < ActiveRecord::Base ? > > While something like this is superficially appealing, it's actually > way more complicated to implement (even Rails doesn't support this > yet) and IMHO adding 'more magic' at this point isn't a brilliant > idea. Actually, it would be enough if I could write this in my active_rbac engine: class ActiveRbac::UserController # ... end This means that the load-routing would have to be changed... > subdirectories on your site). Do you by chance know where to look for that magic in Rails? I want to have a look and could drop half an our searching if you know it off your head. Regards Manuel Holtgrewe
on 2006-02-19 12:27
James, Would you be interested in such a change as I described in my previous email (quoted below). Regards, Manuel Am 04.02.2006 um 12:43 schrieb Manuel Holtgrewe: > Actually, it would be enough if I could write this in my active_rbac > engine: > > class ActiveRbac::UserController > # ... > end > > This means that the load-routing would have to be changed... snip
on 2006-02-19 13:03
On 2/19/06, Manuel Holtgrewe <purestorm@ggnore.net> wrote: > > Actually, it would be enough if I could write this in my active_rbac > > engine: > > > > class ActiveRbac::UserController > > # ... > > end > > > > This means that the load-routing would have to be changed... At the moment, writing this code means that you would get the URL '/active_rbac/user' - this is 'standard' for all controllers in modules, but the controller MUST exist in a subddirectory. From what I can gather, it sounds like you're looking to avoid the requirement that such a controller is in an 'active_rbac' subdirectory. I suspect that doing this would require the engines plugin to provide a fairly complete alternative routing system, and auto-dependency-loading mechanism too, since this type of behaviour isn't supported by what Rails provides *at all*. For me, the price of having to create a few subfolders is by far outweighed by the hassle of having to develop and then support a whole new dependency layer. > > Do you by chance know where to look for that magic in Rails? I want > > to have a look and could drop half an our searching if you know it > > off your head. To understand what Rails is doing when it loads controllers, you need to start by looking at the following files: activesupport/lib/active_support/dependencies.rb actionpack/lib/action_controller/routing.rb (at the auto-generated recognize! method) Personally, I'd like to see the amount of magic that the engines plugin has to perform actually reduce, rather than increase, since it makes it much more likely that we can reuse core behaviour. It also means that developers aren't surprised by the behaviour they see, and can use their experience with 'normal' rails applications to greatest effect when developing engines. Principle of Least Surprise, basically. Aesthetically, i completely sympathise with what you're suggesting, and if the Rails dependency loading system could support something like that easily then it wouldn't be an issue at all... but at the moment, there doesn't seem to be a simple way of doing this. -- * J * ~
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.