[katello-devel] Provider model access issue
Ivan Nečas
inecas at redhat.com
Thu Sep 29 07:26:36 UTC 2011
On 09/29/2011 02:01 AM, Partha Aji wrote:
>
> So I was adding this code to Organization to automatically create a redhat provider when its initialized
>
> class Organization< ActiveRecord::Base
> include Glue::Candlepin::Owner if AppConfig.use_cp
> include Glue if AppConfig.use_cp
> include Authorization
> ......
> before_create :create_locker
> before_create :create_redhat_provider
> .....
> def create_redhat_provider
> self.providers<< Provider.new(:name => "Red Hat",:provider_type=> Provider::REDHAT, :organization => self)
> end
> ....
> end
>
> so when I try to do
> Organization.create! :name=>"foo", :cp_key=>"foo"
>
> I get
>
> NoMethodError: undefined method `new' for Glue::Provider:Module
The problem in this case Glue::Provider module is used. Use ::Provider
to use the model class (:: in the prefix means "absolute" path to the
module)
> from /work/katello/katello/src/app/models/organization.rb:57:in `create_redhat_provider'
> from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.10/lib/active_support/callbacks.rb:425:in `_run_create_callbacks'
>
> Question is how do I ask it to look at the non glue version of the provider? Do I have to do some aliasing trick as in
> class Organization< ActiveRecord::Base
> alias :model_provider Provider
> include Glue::Candlepin::Owner if AppConfig.use_cp
> include Glue if AppConfig.use_cp
> include Authorization
> ....
> def create_redhat_provider
> self.providers<< model_provider.new(:name => "Red Hat", :provider_type=> Provider::REDHAT, :organization => self)
> end
>
> end
>
> Actually even that seems to have some issues :).. Any ideas
>
>
> Partha
>
>
> _______________________________________________
> katello-devel mailing list
> katello-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/katello-devel
--
Regards,
Ivan Necas
Red Hat Czech s.r.o. Brno
More information about the katello-devel
mailing list