Considering you have a state machine, you're probably doing the right thing by looping through the records. Although you could change all the subscriptions (including their state) in the database, you'd be bypassing the state machine and whatever checks and callbacks it has in place.

But, if you really want to bypass the state machine, you could probably do something like this:

unpaid_subs = self.user.subscriptions.unpaid # I'm assuming Payment belongs_to User
unpaid_subs.update_attributes(:payment_id =&gt; self.id, :state =&gt; 'active')


Of course, it would require you to allow mass-assignment of both payment_id and (what I assume is named) state, neither of which sound like good ideas at all.

So you'd have to bypass the state machine and ActiveRecord to directly update the records in the database with some raw SQL... ugh, gross.

So, as I said, you're probably doing the right thing already :)

Improve on an after_create callback with database queries - Ruby on Rails
I am trying to join a 2x4 supporting a workbench tabletop to another to make a backsplash of sorts. Any ideas how to do this without dowels? (No, I can't use 2x8)


