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

Instance of class does not behave like ActiveRecord model #60

Open
lacostenycoder opened this issue Aug 24, 2023 · 0 comments
Open

Instance of class does not behave like ActiveRecord model #60

lacostenycoder opened this issue Aug 24, 2023 · 0 comments

Comments

@lacostenycoder
Copy link

lacostenycoder commented Aug 24, 2023

The error occur when trying to create a new model using ActiveRecord which hasn't been initialized in the config/configurable.yml file.

Ruby Version: 2.6.6
gem version: 0.4.6

Inside a Rails console:

c = Configurable.new
c.name='evil'
c.value='monkey_patch'
t=Time.now.to_s(:db)
c.created_at=t
c.updated_at=t
c.valid?
 c.valid?
NoMethodError: undefined method `[]' for nil:NilClass
from /home/dev/rails/my_app/vendor/cache/gems/configurable_engine-0.4.8/app/models/configurable.rb:125:in `type_of_value'

Looking at the method reveals the bug, which should be an easy fix:

  def type_of_value
    return unless name
    valid = case Configurable.defaults[name][:type] # raises if  Configurable.defaults[name].nil?
    when 'boolean'
      [true, 1, "1", "true", false, 0, "0", "false"].include?(value)
    when 'decimal'
      BigDecimal(value) rescue false
    when 'integer'
      Integer(value) rescue false
    when 'list'
      value.is_a?(Array)
    else
      true
    end
    errors.add(:value, I18n.t("activerecord.errors.messages.invalid")) unless valid
  end
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

1 participant