|
|

01-27-2008, 06:23 AM
|
|
Member
|
|
Join Date: Sep 2006
Posts: 20
|
|
Controllers with the same name in different namespaces
I've been having trouble getting a controller in a namespace with the same name as a controller in the root namespace. A simplified version of the code:
Code:
ActionController::Routing::Routes.draw do |map|
map.resources :editions
map.namespace :organizer do |organizer|
organizer.resources :editions
end
end
class EditionsController < ApplicationController
def index
end
end
class Organizer::EditionsController < ApplicationController
def index
end
end
/editions shows the EditionsController#index action, but /organizer/editions shows the same EditionsController#index action. Rails does not seem to recognize the namespace in this url.
This might well be a bug in Rails, we have some similar trouble running the specs in some situations. But this example does work well in Mongrel on our local machines.
Litespeed consistently routes the namespaced url to the root controller. Do you have any idea what could be the cause of this problem?
|

01-27-2008, 08:56 PM
|
|
LiteSpeed Staff
|
|
Join Date: May 2003
Location: New Jersey
Posts: 7,590
|
|
|
The only difference is that LiteSpeed only set a few Environment variable, not everyone in the shell, if you the route depends on some special environment variable, it must be set under "ruby rails" tab.
For example, "HOME" must be set when use RESTful route.
|

01-28-2008, 08:08 AM
|
|
Senior Member
|
|
Join Date: Jun 2007
Posts: 92
|
|
I have the same problem 
When i do /opt/lsws/bin/lswsctrl restart
my Movie:HomeController isn't used but it use HomeController
But when i killall -9 ruby and litespeed start it from begining it start working ok.
of corse doing /opt/lsws/bin/lswsctrl restart we have problem again 
PS. on apache i don't have problems with this 
Last edited by Grzegorz Derebecki; 01-28-2008 at 08:11 AM..
|

01-28-2008, 01:20 PM
|
|
Senior Member
|
|
Join Date: Jun 2007
Posts: 92
|
|
I find solution (i hope - becous errors can back ;-))
I used Rails preload controllers
Code:
if RAILS_ENV == 'production'
require_dependency 'application'
require_dependency 'movie/base'
require_dependency 'admin/base'
Dir.foreach( "#{RAILS_ROOT}/app/models" ) {|f| $logger.d "r #{f}"; silence_warnings{require_dependency f} if f =~ /\.rb$/}
Dir.foreach( "#{RAILS_ROOT}/app/controllers/movie" ) {|f| $logger.d "r #{f}"; silence_warnings{require_dependency f} if f =~ /\.rb$/}
Dir.foreach( "#{RAILS_ROOT}/app/controllers/admin" ) {|f| $logger.d "r #{f}"; silence_warnings{require_dependency f} if f =~ /\.rb$/}
Dir.foreach( "#{RAILS_ROOT}/app/controllers" ) {|f| $logger.d "r #{f}"; silence_warnings{require_dependency f} if f =~ /\.rb$/}
end
PS. $logger isn't working for rails 2.x
|

01-28-2008, 02:03 PM
|
|
LiteSpeed Staff
|
|
Join Date: May 2003
Location: New Jersey
Posts: 7,590
|
|
|
Does $logger work for rails 2.x when WEBrick or mongrel is used?
Another main difference of Ruby LSAPI is that it forks children processes off a process with initialized Rails framework, I am not sure it is the cause or not.
|

01-28-2008, 02:20 PM
|
|
Senior Member
|
|
Join Date: Jun 2007
Posts: 92
|
|
Quote:
Originally Posted by mistwang
Does $logger work for rails 2.x when WEBrick or mongrel is used?
Another main difference of Ruby LSAPI is that it forks children processes off a process with initialized Rails framework, I am not sure it is the cause or not.
|
>> $logger
=> nil
it don't even works in console 
http://wiki.rubyonrails.org/rails/pages/logger
This is just for controler, model, mailer. Maybe logger is initialized after environment, don't know 
Maybe forked children are problem..
I don't found many simillar isuses only this one http://www.ruby-forum.com/topic/125392
This error is very hard to reproduce becous sometimes it takes many request before it happends.
|

01-28-2008, 02:25 PM
|
|
LiteSpeed Staff
|
|
Join Date: May 2003
Location: New Jersey
Posts: 7,590
|
|
|
I think it maybe related to ruby internal bugs, as I remember, there are bug related to popen() or other functions use fork() then exec(), if exec() failed, the forked children process does not shutdown properly.
|

01-30-2008, 07:20 AM
|
|
Member
|
|
Join Date: Sep 2006
Posts: 20
|
|
I've been doing a bit more research. I've traced the problem to constantize and finally to Object.module_eval
If you replace your constantize method in active_support/lib/inflector.rb with this to get some logging:
Code:
def constantize(camel_cased_word)
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
end
result = Object.module_eval("::#{$1}", __FILE__, __LINE__)
RAILS_DEFAULT_LOGGER.error("constantize '#{camel_cased_word}', result: '#{result}'") if camel_cased_word.ends_with?('Controller')
result
end
You'll see the module_eval sometimes returns the class in the module, and sometimes it doesn't:
My output when the processes have just been restarted is:
constantize 'Organizer::EditionsController', result: 'Organizer::EditionsController'
But later when the error occurs the log output is:
constantize 'Organizer::EditionsController', result: 'EditionsController'
This seems to be a problem in Ruby then?
|

01-30-2008, 07:48 AM
|
|
Member
|
|
Join Date: Sep 2006
Posts: 20
|
|
Thanks Grzegorz, you're suggestion seems to be fixing the issue. I've modified it a bit for Rails 2.0:
Code:
controller_dir = "#{RAILS_ROOT}/app/controllers"
Dir.foreach(controller_dir) { |f| silence_warnings { require_dependency("#{controller_dir}/#{f}") } if f =~ /\.rb$/ }
Dir.foreach("#{controller_dir}/organizer") { |f| silence_warnings { require_dependency("#{controller_dir}/organizer/#{f}") } if f =~ /\.rb$/ }
|

02-07-2008, 08:39 AM
|
|
Senior Member
|
|
Join Date: Jun 2007
Posts: 92
|
|
at first require_dependency is bad, becous it is alias to load with meens that ruby will always reload our class and don't cache it.
I think that i found some solutions about this here:
http://peat.wordpress.com/2006/06/30...our-namespace/
I had movie model, and movie::home controller (movie/home) and i think this was problem
thijs maby you have model organizer ? if yes just change namespace from organizer to organizers and it should works ok.
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 10:18 PM.
|
|