Hi any idea why on model this wont work: class User < ActiveRecord::Base def approve User.find(params[:id]).update_attribute(''status'',"1") end end now I have controller with approve action and I see from the log that sql statement goes and updates that record but status wont change to 1. any ideas ? --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
how exactly do you see this?> I see from the log that > sql statement goes and updates > that record but status wont change to 1so you see the sql statement in the log and the change in the database? but any later request returns the wrong value? or you see the sql statement and nothing changes in the db or does any ''older'' user object not reflect the changes? that would be normal -- Posted via http://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
are you sure the column in which you''re putting the number 1 is a string? (that''s what you''re passing it) -- Posted via http://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yes that was it. it was defined as tinyint i changed it to int. works now thanks man On Feb 13, 9:29 pm, Phil Tayo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> are you sure the column in which you''re putting the number 1 is a > string? (that''s what you''re passing it) > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This may be a bit subtle, but you might want to encapsulate the concept of "approve" into the model. As it stands presently, you''ve essentially mixed some business logic (what it means to approve a user) into your controller. If you ever decide to change that concept you''re going to have to visit the controller... and every other place that relies on User.status = 1 meaning "approved". You might consider something like this: class User def approve update_attributes(:status, 1) end def approved? self.status==1 end ... end By doing this you''ve encapsulated the ''approved'' concept into your model and you can change your mind about the implementation later. For example, maybe you want to use the acts_as_state_machine plugin and introduce the idea of suspending the user. That would likely change how you approve the user and how you test for it. With the code above you can simply say... @user = User.find(params[:id]) @user.approve redirect :back unless @user.approved? On Feb 13, 2:35 pm, KTU <ketuo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> yes that was it. it was defined as tinyint i changed it to int. works > now thanks man > > On Feb 13, 9:29 pm, Phil Tayo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > are you sure the column in which you''re putting the number 1 is a > > string? (that''s what you''re passing it) > > > -- > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---