Hi i had a quick question. if i have a class inside a folder say controllers >> plugins >> test_plugin_conroller.rb, how can i get a reference to this class and call .new on it to create an instance of it. Iv tried doing this: @s = Kernel.const_get("TestPluginController") @sc = @st.new but it sais uninitialized constant TestPluginController, does anyone have a solution? thank you for the help. Brandon -- 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 -~----------~----~----~----~------~----~------~--~---
Why would you have a model inside of the controllers folder? I believe you just need a require statement to load the model file if it''s outside the normal models location. Jason Brandon Trebitowski wrote:> Hi i had a quick question. > if i have a class inside a folder say controllers >> plugins >> > test_plugin_conroller.rb, how can i get a reference to this class and > call .new on it to create an instance of it. Iv tried doing this: > > @s = Kernel.const_get("TestPluginController") > @sc = @st.new > > but it sais uninitialized constant TestPluginController, does anyone > have a solution? thank you for the help. > > Brandon > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
test_plugin_controller.rb *does* contain Class TestPluginController stufff end , doesn''t it? Also: check from the console that that class has actually been loaded by your Rails app. If not, that''s probably the issue. Otherwise, Kernel.const_get("TestPluginController").new *should* work. On 22/09/06, Brandon Trebitowski <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi i had a quick question. > if i have a class inside a folder say controllers >> plugins >> > test_plugin_conroller.rb, how can i get a reference to this class and > call .new on it to create an instance of it. Iv tried doing this: > > @s = Kernel.const_get("TestPluginController") > @sc = @st.new > > but it sais uninitialized constant TestPluginController, does anyone > have a solution? thank you for the help. > > Brandon > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Ok so i moved the plugin to models >> plugins >> test.rb test.rb contains class Test < ActiveRecord::Base end so i did require("models/plugins/test.rb") @s = Kernel.const_get("Test") @sc = @st.new and it said Test is not a class any other ideas? thank you so much for your help -- 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 -~----------~----~----~----~------~----~------~--~---