views:

77

answers:

1

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?

A: 

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
bensie
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.
andy