namespaced controllers

4 views
Skip to first unread message

andy

unread,
Jun 27, 2008, 6:55:05 PM6/27/08
to Phusion Passenger Discussions
Hey guys. First, thanks for passenger, it's a great product. I do have
one issue though: namespaced controllers. I have /users and /admin/
users controllers. When I try to access /admin/users the view breaks
due to an uninitialized instance variable: @users. The same code works
fine under thin, mongrel and webrick so I'm assuming it's a passenger
issue. I've googled but haven't found a solution. Please help, I would
like to continue using passenger, but this is a deal breaker for me. :
(

I'm on the latest version: passenger 2.0.1.

Hongli Lai

unread,
Jun 27, 2008, 7:13:23 PM6/27/08
to phusion-...@googlegroups.com

Have you tried conservative spawning? It might have something to do with
a plugin that doesn't expect preloading.

--
Phusion | The Computer Science Company

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl
Chamber of commerce no: 08173483 (The Netherlands)

Andrew Stone

unread,
Jun 27, 2008, 8:35:28 PM6/27/08
to phusion-...@googlegroups.com
Have you tried conservative spawning? It might have something to do with
a plugin that doesn't expect preloading.

I tried conservative spawning, but still receive the same error:

ActionView::TemplateError (undefined method `each' for nil:NilClass) on line #9 of admin/users/index.html.erb:
6:     <th>Name</th>
7:   </tr>
8:
9: <% @users.each do |user| %>
10:   <tr>
11:     <td><%=h user.login %></td>
12:     <td><%=h user.full_name %></td>

    app/views/admin/users/index.html.erb:9:in `_run_erb_47app47views47admin47users47index46html46erb'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:338:in `send'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:338:in `execute'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template_handlers/compilable.rb:29:in `send'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template_handlers/compilable.rb:29:in `render'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template.rb:35:in `render'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template.rb:22:in `render_template'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:245:in `render_file'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1108:in `render_for_file'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:841:in `render_with_no_layout'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/layout.rb:251:in `render_without_benchmark'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in `render'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/benchmark.rb:8:in `realtime'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in `render'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1157:in `default_render'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1168:in `perform_action_without_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in `call_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in `perform_action_without_benchmark'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:in `passenger_orig_perform_action'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:in `cache'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in `passenger_orig_perform_action'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/railz/request_handler.rb:53:in `perform_action'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `send'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `process_without_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in `process_without_session_management_support'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in `process'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in `process'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in `handle_request'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `synchronize'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/railz/request_handler.rb:38:in `process_request'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/abstract_request_handler.rb:163:in `main_loop'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/railz/application_spawner.rb:307:in `start_request_handler'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/railz/application_spawner.rb:144:in `spawn_application!'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/utils.rb:165:in `safe_fork'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/utils.rb:163:in `fork'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/utils.rb:163:in `safe_fork'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/railz/application_spawner.rb:130:in `spawn_application!'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/utils.rb:165:in `safe_fork'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/utils.rb:163:in `fork'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/utils.rb:163:in `safe_fork'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/railz/application_spawner.rb:129:in `spawn_application!'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/spawn_manager.rb:236:in `spawn_rails_application'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/spawn_manager.rb:219:in `synchronize'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/spawn_manager.rb:219:in `spawn_rails_application'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/spawn_manager.rb:122:in `spawn_application'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/spawn_manager.rb:253:in `handle_spawn_application'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/abstract_server.rb:317:in `__send__'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/abstract_server.rb:317:in `main_loop'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/lib/passenger/abstract_server.rb:168:in `start_synchronously'
    /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.1/bin/passenger-spawn-server:46
 

--
Andrew Stone

Hongli Lai

unread,
Jun 27, 2008, 8:57:27 PM6/27/08
to phusion-...@googlegroups.com
Andrew Stone wrote:
>
> Have you tried conservative spawning? It might have something to do with
> a plugin that doesn't expect preloading.
>
>
> I tried conservative spawning, but still receive the same error:

@users is definitely nil here. Are you sure the relevant query succeeded?

Andrew Stone

unread,
Jun 27, 2008, 9:13:06 PM6/27/08
to phusion-...@googlegroups.com

@users is definitely nil here. Are you sure the relevant query succeeded?

The issue is the Admin::Users controller, the index method isn't being called, so the @users variable isn't being set. 

If I put a log statement in the index method of the controller, it is never output, therefore never being called.
 
--
Andrew Stone

Andrew Stone

unread,
Jun 27, 2008, 9:17:50 PM6/27/08
to phusion-...@googlegroups.com
I would like to add that I have three other controllers with the Admin:: namespace and all exhibit the same issue, so it's not just the Admin::UsersController.


--
Andrew Stone

Wally Valters

unread,
Jun 29, 2008, 10:25:08 AM6/29/08
to phusion-...@googlegroups.com
It is happening with any controller that does not match the default :controller/:action/:id route.

I use a nested dir structure instead of namespaces, but you can adjust my workaround to fit your situation.

As a workaround I put routes in routes.rb like:

map.adminusers 'admin/users/:action/:id' , :controller=> '/admin/users'

This is something to do with passenger, as those routes are not necessary with mongrel / webrick etc.

Andrew Stone

unread,
Jun 29, 2008, 4:25:18 PM6/29/08
to phusion-...@googlegroups.com
On Sun, Jun 29, 2008 at 10:25 AM, Wally Valters <deep...@gmail.com> wrote:
It is happening with any controller that does not match the default :controller/:action/:id route.

I use a nested dir structure instead of namespaces, but you can adjust my workaround to fit your situation.

As a workaround I put routes in routes.rb like:

map.adminusers 'admin/users/:action/:id' , :controller=> '/admin/users'

This is something to do with passenger, as those routes are not necessary with mongrel / webrick etc.


Thanks for the workaround!

-andy


--
Andrew Stone

Andrew Stone

unread,
Jun 29, 2008, 4:47:53 PM6/29/08
to phusion-...@googlegroups.com


As a workaround I put routes in routes.rb like:

map.adminusers 'admin/users/:action/:id' , :controller=> '/admin/users'

This is something to do with passenger, as those routes are not necessary with mongrel / webrick etc.



Unfortunately that didn't work for me and  I wish I had time to dig into it more, but I really don't.  Hopefully the guys at Phusion will fix this issue.

--
Andrew Stone

Hongli Lai

unread,
Jun 30, 2008, 6:03:47 AM6/30/08
to phusion-...@googlegroups.com
Wally Valters wrote:
> It is happening with any controller that does not match the default
> :controller/:action/:id route.
>
> I use a nested dir structure instead of namespaces, but you can adjust
> my workaround to fit your situation.
>
> As a workaround I put routes in routes.rb like:
>
> map.adminusers 'admin/users/:action/:id' , :controller=> '/admin/users'
>
> This is something to do with passenger, as those routes are not
> necessary with mongrel / webrick etc.
>

Do you happen to be using Ruby Enterprise Edition as well? We found an
issue and it might have something to do with that.

Wally Valters

unread,
Jun 30, 2008, 7:33:32 AM6/30/08
to phusion-...@googlegroups.com
The box I'm having issues on is Ubuntu 8.04 with ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]

Andrew Stone

unread,
Jun 30, 2008, 8:23:11 AM6/30/08
to phusion-...@googlegroups.com
I'm using Ruby version:

ruby 1.8.6 (2008-03-03 patchlevel 114) [i686-linux]

To note, I was also getting errors with the inability to find/load namespaced helpers (that correspond with the controller).  So it appears to simply be a namespace load issue.

--
Andrew Stone

Hongli Lai

unread,
Jun 30, 2008, 8:27:12 AM6/30/08
to phusion-...@googlegroups.com
I'm not able to reproduce this problem, so any more information would be
appreciated.

Wally Valters

unread,
Jul 1, 2008, 7:36:08 AM7/1/08
to phusion-...@googlegroups.com
I get it with controllers that inherit from another, and lioe in a subdirectory.  for example:

I have an admin_controller.rb in app/controllers

put a users_controller that inherits from admin_controller in app/admin

try http::host/admin/users.  You get an error relating ot the users action not existing for the admin controller.  Webrick and mongrel have no issue with that setup.  I get around it with named routes, so it is not that big of a deal for me.

Andrew Stone

unread,
Jul 2, 2008, 10:56:05 AM7/2/08
to phusion-...@googlegroups.com
I'm not able to reproduce this problem, so any more information would be
appreciated.


I haven't tested this with mod_passenger yet, but the problem I was having was most likely caused by my gem lockdown and it's controller inspector code.  I have corrected the issue with version 0.5.12.

I just wanted to clarify so people don't get the wrong impression of passenger when this turns up in searches.

Apologies and thanks again for mod_passenger!
andy
--
Andrew Stone
Reply all
Reply to author
Forward
0 new messages