On Jan 17, 10:02 am, Sem Ptiri <[email protected]> wrote:
> klass = Class.new(App) # uses App class to establish_connection to
> externalDB
>
> klass = class_eval do
> #unsure about this. I need to set table_name to same as class name
> ActiveRecord::Base.set_table_name("#{class_name}")
> ActiveRecord::Base.const_set(constant_name, klass)
> end # class_eval
This sounds fishy, you're calling set_table_name on AR::Base, not your
class. just klass.set_table_name 'blah' should be enough
>
> # After creating the class - I want to establish an instance - but it
> says that the class does not exist - more specifically constant doesn't
> exist.
> eval("#{table_name} = #{class_name}.new")
>
> I would love to hear thoughts on this, especially if I'm approaching
> this incorrectly.
>
You haven't created a constant called class_name -
ActiveRecord::Base.const_set(constant_name, klass) would have created
ActiveRecord::Base::Foo.
You probably wanted Object.const_set class_name, klass
Fred
> --
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.