Soft db error handling for duplicate entries? — Rails 3.1 newbie?

I wouldn't recommend checking for the uniqueness and specifically responding to this validation rule via a flash message, this conventionally should be handled by the form's error messages instead. Nonetheless, in the controller actions for creating and updated you could wrap the conditional block which decides where to send the user, with a check for uniqueness first: def create @merchant = Merchant. New params:merchant if Merchant.

Where(:merchant_id => @merchant. Id). Count > 0 flash:error = "The merchant id #{@merchant.Id} already exists" render :create # amend this to :update when applying to the update action else # your normal generated save and render block end end This isn't the cleanest way of achieving your goal, but I think it'll be easiest to understand.

Would really recommend the model validations and form error messages instead, which if you are usung the generated scaffolding, all you need to do is add a model validation and the form throw out the error messages to the user for you: # app/models/merchant. Rb class Merchant.

Having the models check for uniqueness still throws a full page error (albeit a slightly better wording on these errors). – Hopstream Nov 10 at 14:01.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions