warning: toplevel constant Configuration referenced by ActiveRecord::Base::Configuration

60 views
Skip to first unread message

Naveed Alam

unread,
Apr 25, 2016, 2:52:44 AM4/25/16
to rubyonra...@googlegroups.com
Hi,

I am facing the error msg mention in subject, and my theme doesn't
change.

*** init.rb ********
require File.join(File.dirname(__FILE__), "lib", "fedena_theme")
FedenaPlugin.register = {
:name=>"fedena_theme",
:description=>"Fedena Theme"
}

******* /// the line 52 in init.rb showing error /////////////****
52. current_theme =
ActiveRecord::Base::Configuration.get_config_value "Color"




*****fedena_theme.rb **********
# TestPlugin
require 'action_view/helpers/asset_tag_helper'

class FedenaTheme
COLORS = {1 => {:color => "#701288",:accent_color =>
"#4e0d5f",:border_color => "#8d41a0",:sort_order => 16},
2 => {:color => "#39a6ef",:accent_color =>
"#2874a7",:border_color => "#61b8f2",:sort_order => 24},
3 => {:color => "#006290",:accent_color =>
"#004465",:border_color => "#3381a6",:sort_order => 26}
}
FONTS ={1 =>{:text => "Arial", :value => "Arial"},2 =>{:text =>
"Verdana", :value => "Verdana, Arial"},3 =>{:text => "Comic Sans MS",
:value => "Comic Sans MS, Arial"},4 =>{:text => "Georgia", :value =>
"Georgia, Times new Roman"},5 => {:text => "Times new Roman", :value =>
"Times new Roman"},6 => {:text => "Trebuchet MS", :value => "Trebuchet
MS, Arial"},7 => {:text => "Garamond", :value => "Garamond, Times new
Roman"}}
unloadable

def self.general_settings_form
"configuration/theme_select"
end

def self.available_themes
directory = "#{Rails.public_path}/themes"
themes = Dir.entries(directory).select {|entry| File.directory?
File.join(directory,entry) and !(entry =='.' ||
entry == '..') }
return [['Default', 'default']]+themes.collect { |theme|
[theme.titleize, theme] }
end

def self.selected_theme
Configuration.get_config_value("Color")
end


def self.selected_color_value
val = selected_theme
COLORS[val.to_i][:color]
end

end


********* Errors showing
/vendor/plugins/fedena_theme/init.rb:52: warning: toplevel
constant Configuration referenced by ActiveRecord::Base::Configuration


Please help, I dont understand the error and how to resolve this. I
upgraded my App from Rails 2.3.5 to 2.3.10

--
Posted via http://www.ruby-forum.com/.

Greg Navis

unread,
Apr 25, 2016, 9:18:41 AM4/25/16
to rubyonra...@googlegroups.com
The simplest way to trigger this warning (it's not Rails-related BTW) is this:

$ irb
irb(main):001:0> class Foo
irb(main):002:1> end
=> nil
irb(main):003:0> Foo::Array.new
(irb):3: warning: toplevel constant Array referenced by Foo::Array
=> []

So it seems that in addition  to ActiveRecord::Base:Configuration there's another class called Configuration defined at the top level.

Did you define this class? If not, does any of your dependencies define this class?

Best regards
--
Greg Navis
I help small tech companies to scale Heroku-hosted Rails apps.

Naveed Alam

unread,
Apr 25, 2016, 11:08:41 AM4/25/16
to rubyonra...@googlegroups.com
Greg Navis wrote in post #1183062:
> The simplest way to trigger this warning (it's not Rails-related BTW) is
> this:
>
> $ irb
> irb(main):001:0> class Foo
> irb(main):002:1> end
> => nil
> irb(main):003:0> Foo::Array.new
> (irb):3: warning: toplevel constant Array referenced by Foo::Array
> => []
>
> So it seems that in addition to ActiveRecord::Base:Configuration
> there's
> another class called Configuration defined at the top level.
>
> Did you define this class? If not, does any of your dependencies define
> this class?

As I told before in Rails 2.3.5 it was working fine, even though was
showing this warning as well but even then I could change the theme, but
in 2.3.10 its not changing the theme.

Colin Law

unread,
Apr 25, 2016, 12:23:42 PM4/25/16
to Ruby on Rails: Talk
That does not answer the question.

If you search your code for Configuration does it find anything?

Colin

>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1f8d932b6e87d54c17a1b78d975aedf9%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Naveed Alam

unread,
Apr 26, 2016, 12:11:05 AM4/26/16
to rubyonra...@googlegroups.com
Colin Law wrote in post #1183067:
> On 25 April 2016 at 16:08, Naveed Alam <li...@ruby-forum.com> wrote:
>>> => []
>> in 2.3.10 its not changing the theme.
> That does not answer the question.
>
> If you search your code for Configuration does it find anything?
>
> Colin

Yes I have a Configuration Model/Controler below are the links to
controller, and model

https://www.dropbox.com/s/4znjursig0oz7af/configuration_controller.rb?dl=0

https://www.dropbox.com/s/sy6o9c3o4xskj15/configuration.rb?dl=0

Colin Law

unread,
Apr 26, 2016, 4:41:47 AM4/26/16
to Ruby on Rails: Talk
On 26 April 2016 at 05:10, Naveed Alam <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1183067:
>> On 25 April 2016 at 16:08, Naveed Alam <li...@ruby-forum.com> wrote:
>>>> => []
>>> in 2.3.10 its not changing the theme.
>> That does not answer the question.
>>
>> If you search your code for Configuration does it find anything?
>>
>> Colin
>
> Yes I have a Configuration Model/Controler below are the links to
> controller, and model

In that case your simplest solution may be to change the name of the model.

Colin

Naveed Alam

unread,
Apr 26, 2016, 8:14:28 AM4/26/16
to rubyonra...@googlegroups.com
Colin Law wrote in post #1183079:
If I change the model name, then I have to make a lot of changes in
many other Controllers and where its been called
and the migration too.
so I get a lot of error messages.

Can u get any idea from the below tree diagram that if there any change
possible can make it resolve the problem. I changed the configration
folded name in fedena_theme app views but didnt do anything


The Configration model's file tree is
App
|-Views
|_Configuration.rb

And this plugin fedena themes files tree is

App -Vendor - Plugins- fedena_theme
:
:_ views
:_Configuration
: _theme_select.html
:_themes

Colin Law

unread,
Apr 26, 2016, 11:12:46 AM4/26/16
to Ruby on Rails: Talk
On 26 April 2016 at 13:13, Naveed Alam <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1183079:
>> On 26 April 2016 at 05:10, Naveed Alam <li...@ruby-forum.com> wrote:
>>> Yes I have a Configuration Model/Controler below are the links to
>>> controller, and model
>>
>> In that case your simplest solution may be to change the name of the
>> model.
>>
>> Colin
>
> If I change the model name, then I have to make a lot of changes in
> many other Controllers and where its been called
> and the migration too.
> so I get a lot of error messages.

A few global search and replace changes should do it. You don't need
to change the controller or table name if you don't want to. I assume
you have the source under a source control system such as git, and
that you have good automated test coverage, which will make sure you
catch everything.

Colin
Reply all
Reply to author
Forward
0 new messages