-
Notifications
You must be signed in to change notification settings - Fork 386
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
Overriding the setter throws an error #507
Comments
I think this will work if you
The problem is that the setter methods are defined (via That is, in the example above when |
Thank you! |
There is also another way to handle this problem: alias price_from_monetize= price=
def price=(value)
price = value.strip
self.price_from_monetize = price
end |
I'm sorry but im dumbfounded and cant seem to understand how this works. Could you clarify? Thanks. @achernik |
@rockwellll A common idiom is to do Then we override hope this helps |
Currently you cannot override the generated methods and access super ie: ```ruby monetize :price_cents def price=(value) # stuff super # NoMethodError end ``` This happens because the method is defined on the class directly so their is no super method to call. A solution today is to create an alias (`alias :old_price= :price=`) before overriding the method as is recommending in issue RubyMoney#507. Instead, a new module can be created, included into the class, and the methods defined on it allowing `super` to work as expected.
My values come with a lot of weird whitespace and padding so, as recommended by the docs I tried to override the accessors
This resulted in the following error:
Is there a workaround for this? For the moment, i'm going to strip it in the controller, but this definitely feels like something the model should be doing.
The text was updated successfully, but these errors were encountered: