thanks for the help so far... Haven't fully made up my mind but I believe I will go with the latter option to keep performance reasonable. As I am still trying to learn ruby/rails (first time learning a programming language, its been a solid year but...)Here are a couple questions to get me to my next step:
While I can run the call user.redemptions.count, I don't actually want to use that to keep a running total of a given users "points"
Seems that I should add a "points" field to the User model and increment the code owner's.points value.
@code = Code.find_by_code(params[:redemption][:code])
@redemption = @code.redemptions.find_or_initialize_by_user_id(current_user.id)
if @redemption.new_record? && @redemption.save
redirect_to bands_url, :notice => "Redemption Successful."
redirect_to bands_url, :notice => "This redemption has already been used!"
redirect_to bands_url, :notice => "There's been a problem. We could not redeem this code."
This is my redemptions controller#create. It seems that I should add a before/after_create callback (I don't think it matters in this case) and do something like:
self is the redemptions, redemptions belong to users so self.user.increment(points) would increment the user.points attribute of the code creation user.
Does any of that make sense?
Walked away and wondered if I could call the increment method on the controller before the redirect. Something like
Tried the controller route and it did not appear to save any increment to the User.
EDIT AGAIN AGAIN
Ok I have been able to increment the points but to the wrong user. ITs updating the the redeeming users points.
This saved like I said, just to the wrong user.
I tried modifying to:
but this returns: undefined method `user' for nil:NilClass
Redemptions has_one code, code belongs to user so I figured I could write: redemption.code.user
Last edited by tjsherrill (2012-01-21 13:27:58)