0

这是我的信用卡模型:

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......我如何摆脱钥匙?

4

1 回答 1

1

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

于 2012-09-07T20:51:20.797 回答