0

I have a record that needs to be validated before doing some action. Am I required to use a "valid?" method if I'm doing it with after_create?

For example, I have in my User model:

def after_create
  if valid?
  ...
  end
end

I thought it wasn't necessary to put in the valid method, but my application is telling me otherwise. Any idea?

1 Answer 1

4

You do not need the if valid? declaration there because after_create gets called after the record has already been validated (and created).

What do you mean your application is telling you otherwise?

Also, for the callback methods, you should use something like:

after_create :call_my_method

private

def call_my_method
  # Do cool stuff
end
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks bensie. I'm using the Restful Authentication plugin and it seems like it's using after_create before the record is validated, so it must be my programming then since I'm the only one having the issue. Thanks so much for your answer.

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.