This is easier (or at least cleaner) to do with lifecycles. http://gist.github.com/316159
That's code I wrote for a more complicated user lifecycle but from it, you should be able to get the idea. On Feb 26, 4:19 am, Mark Jones <[email protected]> wrote: > Hi, > > I'll give basic rundown of what I'm trying to achieve and the problem > I have.. > > 1) Unless a user has accepted the Site Terms and Conditions they > cannot proceed to parts of the site (tnc is part of user model) > 2) The User is presented with a page just showing a page to accept the > TNC , i.e a custom page just showing the tnc field of the user model. > 3) When User has accepted this I want to write the Time to the DB and > redirect to Home Page, currently this will go to the User Info page > after user update. > > I have a the following in the user model: > --------------- > def acceptedtnc? > if self.accepted_tnc && self.accepted_tnc_changed? > User.update(self.id, {:accepted_at => Time.now}) > return true > else > return false > end > end > --------------- > > which is called from the User controller > > --------------- > before_filter :check_tncaccept > > def check_tncaccept > > # Check if user has just accepted TNC's if they have then redirect to > Home and show a flash message > return unless current_user.acceptedtnc? > flash[:notice] = "You have now sucessfully accepted the Terms and > Conditions" > redirect_to "/" > end > > --------------- > > However the "self.accepted_tnc_changed" method is not flagged BUT if I > have the following in the user_observer model in after_update then it > does run the acceptedtnc2 function > > if user.accepted_tnc = "t" && user.accepted_tnc_changed? > user.acceptedtnc2 > end > > I'm stuck as to go about figuring this out so any help appreciated.. > > Thanks > > Mark -- You received this message because you are subscribed to the Google Groups "Hobo Users" 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/hobousers?hl=en.
