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

Does not support :defaults and :class_name at same time #57

Open
aysark opened this issue May 30, 2014 · 4 comments
Open

Does not support :defaults and :class_name at same time #57

aysark opened this issue May 30, 2014 · 4 comments

Comments

@aysark
Copy link

aysark commented May 30, 2014

I want to be able to have validations on settings and also have defaults for them. It would seem this can't be done due to line 27 in configuration.rb.

@ledermann
Copy link
Owner

Sorry, for delay - but what about this:

class Project < ActiveRecord::Base
  has_settings :info, :class_name => 'ProjectSettingObject' do |s|
    s.key :dashboard, :defaults => { :theme => 'blue', :view => 'monthly', :filter => false }
    s.key :calendar,  :defaults => { :scope => 'company'}
  end
end

IMHO it's already possible. Maybe I don't understand your intention. Feel free to enhance your PR #58 with an additional test. BTW, your PR currently breaks the tests.

@frostblooded
Copy link

frostblooded commented Aug 28, 2016

I have stumbled with this issue also. Yes, it is possible the way you are showing it, but it would be nice of a key can have a separate class name like this:

has_settings do |s|
  s.key :call, defaults: { interval: '15' }
  s.key :shift, defaults: { start: '12:00', end: '13:00' },
                class_name: 'SiteTimeSettingObject'
end

@eduanttunes
Copy link

eduanttunes commented Feb 22, 2017

@frostblooded @ledermann it doesn't work... how to set multiple keys, defaults and class names?

I need something like:

has_settings :class_name => 'Class_One' do |s|
s.key :appointment, :defaults => { :time => '01:00', :price => '100.00' }
end

has_settings :class_name => 'Class_Two' do |s|
s.key :website, :defaults => { :about_text => 'Coming soon.', :color => '#d5dadc' }
end

But the second has_settings overrides the first. I have to use different classes to validate.

@ignaciodm
Copy link

@eduanttunes How did you solve this issue?

@ledermann Any update on this?

Thanks guys

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

5 participants