Rails 3:在flash消息中显示错误完整消息

时间:2012-09-07 20:42:44

标签: ruby-on-rails-3 error-handling custom-validators

这是我的CreditCard模型:

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

当用户提交CreditCard时,验证就会发生,这就是我在flash消息中设置错误的方法:

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

但出于某种原因,当视图中显示flash[error]时,显示的方式如下:Credit card base Last Name is required ...如何摆脱密钥?

1 个答案:

答案 0 :(得分:1)

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