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

Default settings still working? #94

Open
shrinathaithal opened this issue Nov 27, 2018 · 3 comments
Open

Default settings still working? #94

shrinathaithal opened this issue Nov 27, 2018 · 3 comments

Comments

@shrinathaithal
Copy link

Going by the README, I did try this -

 has_settings do |s|
    s.key :notifications, :defaults => { :email_frequency => "7" }
  end

When I do User.find(9).to_settings_hash, I do see the default applied.
However, when I try User.find(9).settings(:notifications), I just see a {} for value.

Digging in the code, I see that line 16 & 18 of base.rb are initializing just the var with empty stuff, nothing in it. I added value: self.class.default_settings[var] when it is building, it starts to work fine now.

Am I not seeing this magic dust somewhere? Happy to raise pull request if there is a bug here.

@ajays1991
Copy link

looks like still not working

@charlesemarsh
Copy link

Not working for me either

@farkmarnum
Copy link
Contributor

This is because the defaults settings are only returned when you call a method on the SettingObject.

So, this will just return a SettingObject that indicates that nothing has been set for the user yet:

user.settings(:notifications)
# => #<RailsSettings::SettingObject id: nil, var: "notifications", value: {}, target_type: "User", target_id: 9, created_at: nil, updated_at: nil>

Whereas calling the method will return the default value:

user.settings(:notifications).email_frequency
# => 7

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

4 participants