Rails 3: Handle ActiveRecord::RecordNotUnique Exception

后端 未结 3 1778
臣服心动
臣服心动 2020-12-28 18:31

How can I handle ActiveRecord::RecordNotUnique exception in the controller? Thanks

Edit: I\'m getting that exception when generating an

3条回答
  •  心在旅途
    2020-12-28 19:03

    begin
      # do stuff
    rescue ActiveRecord::RecordNotUnique
      # handle the exception however you want to
    end
    

    http://ruby-doc.org/docs/ProgrammingRuby/html/tut_exceptions.html

    You could also use rescue_from if it's something you need to deal with often.

提交回复
热议问题