Question

Keep getting Syntax Error in Controller due to custom validations. Wondering how exactly I would implement custom validations within Refinery.

Error

/Users/bklane/Documents/code/codery/syrsp_two/vendor/extensions/quotes/app/models/refinery/quotes/quote.rb:18: syntax error, unexpected tIDENTIFIER, expecting keyword_end
      validate :in_future?

quote.rb

module Refinery
  module Quotes
    class Quote < Refinery::Core::BaseModel
      # require 'postmaster'
      self.table_name = 'refinery_quotes'

      attr_accessible :company, :due_by, :email, :f_name, :l_name, :phone, :pickup, :ship_city, :ship_line_1, :ship_line_2, :ship_contact, :ship_company, :ship_state, :ship_zip, :email_sent, :note, :position

      alias_attribute :message, :note

      alias_attribute :name, :company

      # Add some validation here if you want to validate the user's input
      # We have validated the first string field for you.
      validates_presence_of :email, :phone, :f_name, :l_name
      validates_inclusion_of :pickup, in: [true, false]
      validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i\

      # validations not working below
      validate :in_future?
      # validate :parse_phone
      # validate :validate_address

      def in_future?
        errors.add(:due_by, "Order cannot be due in the past") unless (due_by.present? && (1 === (due_by <=> Date.today)))
      end
    end
  end
end
Was it helpful?

Solution

The trailing \ in your regular expression on line 17 is the cause of the syntax error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top