Hello--
On Aug 9, 2009, at 9:39 AM, boblu wrote:
>
> I have a module like this:
>
> module Controller
> module LocaleModels
> def self.included(base)
> base.send :include, InstanceMethods
> end
>
> module InstanceMethods
> def locale_Lexeme; constantize_model('Lexeme') end
> def locale_Synthetic; constantize_model('Synthetic') end
> def locale_Property; constantize_model('Property') end
>
> private
> def constantize_model(common_part)
> eval(I18n.locale.capitalize + '::' + common_part).constantize
> end
> end
> end
> end
>
> But I kept getting
>
> NoMethodError (undefined method `constantize' for #<Class:0x2483b0c>)
>
> I guess I cannot use 'constantize' in a custom module.
>
> But can you please offer some workaround?
This may not be the problem, but why are you using eval?
ActiveSupport::CoreExtensions::String::Inflections defines constantize
as a method on String. It would seem to me that this would work:
(I18n.locale.capitalize + '::' + common_part).constantize
However, if you are looking for a class, investigate classify instead.
Maybe there's something I'm missing here that requires use of eval?
What happens in script/console if you type the expression in?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---