Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `default_settings' for #<Class:0x007f83b8c57ab8> #81

Open
adiakritos opened this issue Nov 20, 2017 · 3 comments

Comments

@adiakritos
Copy link

It appears that the target class isn't being assigned a default_settings hash. Why might this be the case?

I've tried it on two different models in our codebase.

Using Rails 3.2.22 and Ruby 2.3.3

@olliebennett
Copy link

Does a normal call (such as @record.settings(:some_configured_type)) work? Interested to see whether there's a general problem with the gem loading or whether it's specific to the default_settings hash.

Which gem version are you using?

@benpixel
Copy link

benpixel commented Aug 1, 2018

I'm having a similar problem using 2.4.3. Here's an example:

shop = Shop.first
settings = RailsSettings::SettingObject.find_by(target_id: shop.id, target_type: "Shop")
# settings returns RailsSettings::SettingObject with all settings thats good
# settings.discount also returns good data
settings.blank? # this gives error, also .present? etc

Error:

NoMethodError: undefined method `default_settings' for #<Class:0x00007f9bc74aac58>
Did you mean?  default_extensions
from /Users/benjam1n/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activerecord-5.2.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing'

@olliebennett
Copy link

That's strange...

  • Have you restarted the server (or spring for example) after installing the gem?

  • Have you configured the relevant default values in has_settings? Here's my user config;

    # user.rb
    has_settings do |s|
      s.key :email_notifications, defaults: {
        promotions: false,
        newsletters: true
      }
    end

    Then I can do the following;

    [1] pry(main)> User.first.default_settings
      User Load (6.8ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1  [["LIMIT", 1]]
    => {:email_notifications=>
       "promotions"=>false,
       "newsletters"=>true}
    

Are you able to configure a model in the same, minimal way and see if you can reproduce?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants