KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How can I handle ActiveRecord::RecordNotUnique exception in the controller? Thanks Edit : I'm getting that exception when generating an unique code. I can handle the exception in the application_controller.rb but what I really want is to code to be generated again and that must be done in the controller. generate_code @couponcode = Couponcode.new(:user_id => current_user.id, :code => @code) Edit2 : generate_code begin @couponcode = Couponcode.new(:user_id => current_user.id, :code => @code) rescue ActiveRecord::RecordNotUnique #generate_code @code = "111-11111" @couponcode = Couponcode.new(:user_id => current_user.id, :code => @code) end
Tags (comma-separated)
Save Edits
Cancel