Having a slight issue with this "superclass mismatch for class" error. I''m developing a plugin and having to load controllers dynamically. Like: class MyController < ApplicationController end load(''my_controller.rb'') @klaz = Object.const_get(''MyController'') When I do this, It works the FIRST time, be then on subsequent requests I am getting "superclass mismatch for class MyController" Any ideas? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Aaron Smith wrote:> Having a slight issue with this "superclass mismatch for class" error. > I''m developing a plugin and having to load controllers dynamically. > Like: > > class MyController < ApplicationController > end > load(''my_controller.rb'') > @klaz = Object.const_get(''MyController'') > > When I do this, It works the FIRST time, be then on subsequent requests > I am getting "superclass mismatch for class MyController" > > Any ideas?I just tried one other thing. If the controller class extends ActionController::Base instead of ApplicationController, it works fine: This works every time: class MyController < ActionController::Base end load(''my_controller.rb'') @klaz = Object.const_get(''MyController'') What would be causing the failure when extending from ApplicationController? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m experiencing the exact same issue. After reading your post, I''ve confirmed that my code also works if inheriting ActionController::Base and not ApplicationController. I also have subfolders within the controllers folder, and they all load fine, even when inheriting ApplicationController. Only the controllers in the controllers folder produce the superclass mismatch error on subsequent calls. After a full day of debugging this, I am no closer to finding the issue. I have however, found a workaround. For some reason calling Object.const_get(''MyController'') before load(''MyController'') eliminates the error. It''s a horrible workaround, but I must move on. If anyone finds the real solution, I''d love to know what it is so I can get rid of this hack. On Jun 30, 2:36 pm, Aaron Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Having a slight issue with this "superclassmismatchfor class" error. > I''m developing a plugin and having to load controllers dynamically. > Like: > > class MyController < ApplicationController > end > load(''my_controller.rb'') > @klaz = Object.const_get(''MyController'') > > When I do this, It works the FIRST time, be then on subsequent requests > I am getting "superclassmismatchfor class MyController" > > Any ideas? > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You''re trying to redefine a class (through multiple but different requires most likely) with different subclasses. Try this out: file1.rb: class Parent1 end class Tester < Parent1 end file2.rb class Parent2 end class Tester < Parent2 end test.rb require ''file1'' require ''file2'' # => Superclass Mismatch for Tester file2.rb This error is slightly cryptic but does make sense when you know what it means. The error is named as such because of the open classes nature of Ruby. Were the superclasses the same, then it''d be simply adding functionality to an existing class. However, as the classes are of different types, Ruby can''t know what to do with them and thus dies. So make sure you''re not trying to munge up the Object namespace with classes named the same but are different types. I''m not sure of the exact reason as to why ApplicationController fails and ActionController::Base works, but do remember that Rails does a lot of strange things to the ObjectSpace. Jason On 7/2/07, Kevin Tyll <kevintyll-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I''m experiencing the exact same issue. After reading your post, I''ve > confirmed that my code also works if inheriting ActionController::Base > and not ApplicationController. I also have subfolders within the > controllers folder, and they all load fine, even when inheriting > ApplicationController. Only the controllers in the controllers folder > produce the superclass mismatch error on subsequent calls. > > After a full day of debugging this, I am no closer to finding the > issue. I have however, found a workaround. For some reason calling > Object.const_get(''MyController'') before load(''MyController'') > eliminates the error. > > It''s a horrible workaround, but I must move on. > > If anyone finds the real solution, I''d love to know what it is so I > can get rid of this hack. > > On Jun 30, 2:36 pm, Aaron Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > Having a slight issue with this "superclassmismatchfor class" error. > > I''m developing a plugin and having to load controllers dynamically. > > Like: > > > > class MyController < ApplicationController > > end > > load(''my_controller.rb'') > > @klaz = Object.const_get(''MyController'') > > > > When I do this, It works the FIRST time, be then on subsequent requests > > I am getting "superclassmismatchfor class MyController" > > > > Any ideas? > > > > -- > > Posted viahttp://www.ruby-forum.com/. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---