Ich möchte das customer_price >= my_price
validieren. Ich habe versucht, die folgenden:Schienen 3: Wie validiere ich A <B, wobei A und B beide Modellattribute sind?
class Product < ActiveRecord::Base
attr_accessor :my_price
validates_numericality_of :customer_price, :greater_than_or_equal_to => my_price
...
end
(customer_price
ist eine Spalte in der Products
Tabelle in der Datenbank, während my_price
nicht.)
Hier ist das Ergebnis:
NameError in ProductsController#index
undefined local variable or method `my_price' for #<Class:0x313b648>
Was ist der richtige Weg, dies in Rails 3 zu tun?
vielleicht brauchen Sie nur einen Doppelpunkt my_price ein Symbol zu machen? – hdgarrood
mögliche Duplikate von [Wie implementiert Min/Max-Validator in Rails 3?] (Http://stackoverflow.com/questions/4416278/how-to-implement-min-max-validator-in-rails-3) –