rails-settings icon indicating copy to clipboard operation
rails-settings copied to clipboard

has_settings for sub classes doesn't work

Open SanderMander opened this issue 9 years ago • 3 comments

in case when A < ActiveRecord::Base and B < A has_settings doesn't work correct inside B. Probably this is caused because target_type use base_class which will return A even if called inside B. so _target_class will return wrong class and settings always will be nil.

I think overriding of target_type should solve problem, but I have not tested it well yet.

    def target_type
      target.class.to_s
    end

SanderMander avatar Jul 29 '15 09:07 SanderMander

@SanderMander facing same issue. your monkey patch worked. will work on a PR to support STI classes. The workaround is detailed here

kitwalker12 avatar Dec 18 '15 05:12 kitwalker12

@kitwalker12 @SanderMander facing same issue. Any news about fix ?

zauzaj avatar Jul 18 '18 08:07 zauzaj

RailsSettings::SettingObject.class_eval do
  private
  def _target_class
    target.class
  end
end

ruvzi avatar Jul 21 '18 10:07 ruvzi