使用rescue_from显示视图中的错误消息

时间:2016-04-12 17:27:08

标签: ruby-on-rails

我的控制器中有rescue_from

rescue_from StandardError, with: :shipping_error

这是我的控制器中的create操作

def create
  shop = ShippingMethod.create(shipping_method_params)
  assigned_shop = assign_shipping_variables(shop)
  if assigned_shop.valid?
    redirect_to edit_shipping_method_path(assigned_shop)
  else
   shipping_error
  end
end

这是shipping_error同一控制器中的私有方法

def shipping_error
  @error = "Hey don't touch me there"
  render :back
end

在我的模型中,我验证了numericality

最后,我在一个名为_tab的部分中有一个表单,我只想在验证失败时显示@error ..我似乎无法在那里得到它。

思想?

0 个答案:

没有答案
相关问题