On Jun 11, 4:45 pm, Max Williams <[email protected]>
wrote:
> I know that usually when people say 'i think i found a bug in
> rails/ruby' they've done something dumb. I'm wondering if this is the
> case here, but this does seem like a genuine rails bug to me.
>
> In my user model i have a few different before_create callbacks. In one
> of them, if it happens to return false (just because the last statement
> in it evaluated to false), then the saving gets blocked - i can see the
> db transaction rolling back. However, this doesn't affect the results
> of calling .valid? on the object, so i get this situation:
>
It's a feature. See
http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
(under Canceling callbacks)
Fred
> new_user.valid?
> => true
> new_user.save
> => false
> new_user.errors.full_messages
> => []
>
> This has caused me a considerable amount of beard-tugging to track this
> down.
>
> Now, i was under the impression that before_create doesn't care what's
> returned by the method it calls, and for my other before_save callbacks
> it doesn't seem to make any difference - just this one. It's definitely
> the return value because if i put 'true' as the last line of the
> callback method then everything is fine. I change it to 'false' and
> everything's not-fine again.
>
> I'm in rails 2.2.2.
>
> Can anyone shed any light on this?
>
> thanks
> max
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---