1

I have the following action to confirm a PIN code.

def create
  @confirm = User.where(:email => params[:user][:email]).last
  errors[:base] << "Subscription not found" if @confirm.nil?
  respond_with(@confirm)
end

If the object doesn't exist I'm getting the following error

NameError in ConfirmsController#create

undefined local variable or method `errors' for #<ConfirmsController:0x007f921de173d0>

Why it doesn't recognize errors and how can I handle error for this case?

1
  • errors need to be attached to an ActiveModel object Commented Jun 5, 2012 at 18:19

2 Answers 2

1

Errors as you are using them are typically on the ActiveRecord model. If you want to display an error message try using the flash method.

Sign up to request clarification or add additional context in comments.

Comments

0
@confirm.errors[:base] << ...

should do the trick

1 Comment

unfortunately @confirm is nil in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.