Skip to content

Instantly share code, notes, and snippets.

@robins35
Last active January 16, 2019 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robins35/037d32e052d3099d8ce317c9c2c6c19d to your computer and use it in GitHub Desktop.
Save robins35/037d32e052d3099d8ce317c9c2c6c19d to your computer and use it in GitHub Desktop.
# Relevant part of GlobalUser model, the error occurs on line 10, saying there is no super method,
# even though it should be defined on line 6 (and appears to be defined, in the below tests).
cp_typed_hash :settings do |h|
# Settings hash, text based json column
h.bool :receive_direct_message_alerts, :default => false # This is where the original method is defined, I've confirmed it exists.
end
def receive_direct_message_alerts=(flag)
staff.first.is_admin? && super(flag)
end
# Console session showing error, before removing the method :receive_direct_message_alerts=
>> g = GlobalUser.last;
>> g.receive_direct_message_alerts # Getter method works fine
=> true
>> g.receive_direct_message_alerts = false # Setter method errors out, saying there is no super method
NoMethodError: super: no superclass method `receive_direct_message_alerts=' for #<GlobalUser:0x7f64a784ea50>
from /home/scriptonaut/camp52/lib/rails/002_active_record/attribute_methods.rb:255:in `method_missing'
from /home/scriptonaut/camp52/app/models/membership/global_user.rb:374:in `receive_direct_message_alerts='
from (irb):7
# Relevant part of GlobalUser model, the error above suggests that there shouldn't be a
# :receive_direct_message_alerts= method defined when I comment it out, since the super
# method is missing when it's uncommented. However when I comment out it out, the setter
# method defined on line 11 works just fine.
cp_typed_hash :settings do |h|
# Settings hash, text based json column
h.bool :receive_direct_message_alerts, :default => false
end
# def receive_direct_message_alerts=(flag)
# staff.first.is_admin? && super(flag)
# end
# After commenting out the :receive_direct_message_alerts= method overrive, the previous error would
# suggest that the method would no longer be defined. However after commenting it out, the setter
# method still exists, see on line 8, and line 13.
>> g = GlobalUser.last;
?> g.receive_direct_message_alerts
=> true
>> g.receive_direct_message_alerts = false # This should error, because there wasn't a superclass method before
=> false
>> g.receive_direct_message_alerts
=> false
# Below we see that after removing that method override, the setter method still exists.
>> (g.methods.sort - methods).any? { |m| m == "receive_direct_message_alerts=" }
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment