Rails show validate errors on create self class custom -


i have class filter_report.rb

class filterreport   include activemodel::validations   attr_accessor :company_id    validates :company_id, presence: true    def initialize(options = {})     options.each {       |k,v|       self.send( "#{k.to_s}=".intern, v)     }   end 

how call filterreport class show validate

i want showw

report = filterreport.new report.company_id = "" report.valid? => false report.save => undefined save 

i want know message of validation presence.

"company can't blank"

if @ documentation activemodel::validations, you'll find errors:

returns errors object holds information attribute error messages.

errors implements whole slew of different methods, want #[]:

report.errors[:company_id] # => "company can't blank" 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -