Hi all, I have an app where I have Users, users upload images, post blog comments, etc. All has been fine until we now need to disable a user. Which means all calls to User.find_by_id() now need to exclude any disabled users. Also searches for such things as photos and blog comments need to exlude those belonging to disabled users. Aside from going through the whole application and addition conditions to calls such as find_by_id (and other such searches), is there some clean way that I could add this requirement? I simply need to exclude user, comment and photo searches of disabled users. Hope this makes sense. Any help would be appreciated. Thanks, Diego --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Diego, you can do the following: a) add a field to the user table called ''disabled'' and this field is set to ''false'' by default. b) change how you perform the find user = User.find( :first, :conditions => [ "disabled = ? and id ?", "false", input_id ] ) c) update your admin area so that you can simply disable a user Good luck, -Conrad On 2/26/07, Diego <dbarros-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I have an app where I have Users, users upload images, post blog > comments, etc. All has been fine until we now need to disable a user. > Which means all calls to User.find_by_id() now need to exclude any > disabled users. Also searches for such things as photos and blog > comments need to exlude those belonging to disabled users. > > Aside from going through the whole application and addition conditions > to calls such as find_by_id (and other such searches), is there some > clean way that I could add this requirement? I simply need to exclude > user, comment and photo searches of disabled users. > > Hope this makes sense. > > Any help would be appreciated. > > Thanks, > Diego > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Conrad. Appreciate the response. On Feb 27, 7:07 pm, "Conrad Taylor" <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> HiDiego, you can do the following: > > a) add a field to the user table called ''disabled'' and this field is > set to ''false'' by default. > > b) change how you perform the find > > user = User.find( :first, :conditions => [ "disabled = ? and id > ?", "false", input_id ] ) > > c) update your admin area so that you can simply disable a user > > Good luck, > > -Conrad > > On 2/26/07,Diego<dbar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi all, > > > I have an app where I have Users, users upload images, post blog > > comments, etc. All has been fine until we now need to disable a user. > > Which means all calls to User.find_by_id() now need to exclude any > > disabled users. Also searches for such things as photos and blog > > comments need to exlude those belonging to disabled users. > > > Aside from going through the whole application and addition conditions > > to calls such as find_by_id (and other such searches), is there some > > clean way that I could add this requirement? I simply need to exclude > > user, comment and photo searches of disabled users. > > > Hope this makes sense. > > > Any help would be appreciated. > > > Thanks, > >Diego--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi there ;) Another tips that could be usefull : use the "conditions" in the linked tables. For example, after adding the disabled field in the user table, if you have a file table with a link "has_many" you can write : class File < ActiveRecord::Base has_many :users, :conditions => ''disabled = false'' end Then you will only retrieve files with users that complet the condition ''disabled = false''. And you will not have to rewrite the User.find() in each linked table. You can then access all the disabled users via the User class, but not via the linked tables. Tony -- 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 -~----------~----~----~----~------~----~------~--~---
njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-01 12:26 UTC
Re: Injecting SQL conditions to models?
I''m doing something similar, except I''ve taken it a step further. Rather than having a boolean field, I have an integer field (technically a foreign key, although the meanings of the numbers are hard-coded as well) which means I can have different levels of blocking. 0 means "active", 1 means "temporarily blocked" (still receives email alerts and stuff, but temporarily can''t log in), 2 means "frozen" (still appears as a member in the system, but doesn''t receive emails and can''t log-in), and 3 means deleted (completely hidden from everyone, but still on the system to maintain database integrity, and in case deletion was in error). Hope this helps, -N On 01/03/07, Tony <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi there ;) > > Another tips that could be usefull : use the "conditions" in the linked > tables. > > For example, after adding the disabled field in the user table, if you > have a file table with a link "has_many" you can write : > > class File < ActiveRecord::Base > has_many :users, > :conditions => ''disabled = false'' > end > > Then you will only retrieve files with users that complet the condition > ''disabled = false''. And you will not have to rewrite the User.find() in > each linked table. > You can then access all the disabled users via the User class, but not > via the linked tables. > > Tony > > -- > 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 -~----------~----~----~----~------~----~------~--~---