Question

Here is my CreditCard model:

validate :name_is_split_properly
  private
    def name_is_split_properly
      if last_name.blank?
        self.errors[:base] << "Last Name is required"
      end
    end

When a user submits a CreditCard, the validation takes place and this is how I am setting the error(s) in a flash message:

flash[:error] = current_order.errors.full_messages.join('\n')
redirect_to new_order_path(:client_id => params[:client_id])

But for some reason when the flash[error] is displayed in the view, this is how its displayed: Credit card base Last Name is required... how do I get rid of the key?

Was it helpful?

Solution

Try errors.add(:base, "Last Name is required")

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