Say I have a boolean field called hidden, which is set to true if I want to hide say a product or a task. Now I only want to hide the record for the customer side of the application and not admin side. So where do I put the logic that says either find all records or records where hidden <> 1? I could put it in the controller: @categories = Category.find(:first, :conditions => [''hidden <> 1 AND id = ?'', params[:id]]) but something tells me it should be in the model... Now I could put in the model so that any calls to find return only non-hidden fields. But then my admin side is blinded to hidden records and they are effectivly badly deleted instead of hidden. I''m keen to know how people go about this :) I''m sure there are maybe a few ways of doing this! Cheer K.
Kris, Maybe you could implement a find_including_hidden and/or find_without_hidden function in your model wich calls the find method. Jaap On 10/21/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote:> Say I have a boolean field called hidden, which is set to true if I want > to hide say a product or a task. > Now I only want to hide the record for the customer side of the > application and not admin side. > So where do I put the logic that says either find all records or records > where hidden <> 1? > > I could put it in the controller: > @categories = Category.find(:first, :conditions => [''hidden <> 1 AND id > = ?'', params[:id]]) > > but something tells me it should be in the model... > > Now I could put in the model so that any calls to find return only > non-hidden fields. But then my admin side is blinded to hidden records > and they are effectivly badly deleted instead of hidden. > > I''m keen to know how people go about this :) I''m sure there are maybe a > few ways of doing this! > > Cheer K. > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
So basically abstract the logic out of the controller and in to the model... I guess this is like the Depot example in the Rails book where an action called Salable_items is put in the Products model. This action does a find with a condition so only products that have the date_available field set in the past are returned. Cheers K Jaap Schreurs wrote:>Kris, > >Maybe you could implement a find_including_hidden and/or >find_without_hidden function in your model wich calls the find method. > >Jaap > >On 10/21/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote: > > >>Say I have a boolean field called hidden, which is set to true if I want >>to hide say a product or a task. >>Now I only want to hide the record for the customer side of the >>application and not admin side. >>So where do I put the logic that says either find all records or records >>where hidden <> 1? >> >>I could put it in the controller: >>@categories = Category.find(:first, :conditions => [''hidden <> 1 AND id >>= ?'', params[:id]]) >> >>but something tells me it should be in the model... >> >>Now I could put in the model so that any calls to find return only >>non-hidden fields. But then my admin side is blinded to hidden records >>and they are effectivly badly deleted instead of hidden. >> >>I''m keen to know how people go about this :) I''m sure there are maybe a >>few ways of doing this! >> >>Cheer K. >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > >
Exactly :-) . In addition, you could "defensively" extend the find method so standard only non-hidden fields are found, and only when explicitly calling find_unhidden you get them all :-) Jaap On 10/23/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote:> So basically abstract the logic out of the controller and in to the > model... I guess this is like the Depot example in the Rails book where > an action called Salable_items is put in the Products model. This action > does a find with a condition so only products that have the > date_available field set in the past are returned. > > Cheers K > > Jaap Schreurs wrote: > > >Kris, > > > >Maybe you could implement a find_including_hidden and/or > >find_without_hidden function in your model wich calls the find method. > > > >Jaap > > > >On 10/21/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote: > > > > > >>Say I have a boolean field called hidden, which is set to true if I want > >>to hide say a product or a task. > >>Now I only want to hide the record for the customer side of the > >>application and not admin side. > >>So where do I put the logic that says either find all records or records > >>where hidden <> 1? > >> > >>I could put it in the controller: > >>@categories = Category.find(:first, :conditions => [''hidden <> 1 AND id > >>= ?'', params[:id]]) > >> > >>but something tells me it should be in the model... > >> > >>Now I could put in the model so that any calls to find return only > >>non-hidden fields. But then my admin side is blinded to hidden records > >>and they are effectivly badly deleted instead of hidden. > >> > >>I''m keen to know how people go about this :) I''m sure there are maybe a > >>few ways of doing this! > >> > >>Cheer K. > >> > >>_______________________________________________ > >>Rails mailing list > >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >>http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > >_______________________________________________ > >Rails mailing list > >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Great stuff thanks, I did consider over-riding the find method so it didnt include hidden fields and then making a find_with_hidden for use by the admin... But I think I will not tamper with find and just create one new method called find_without_hidden :) thanks! Jaap Schreurs wrote:>Exactly :-) . > >In addition, you could "defensively" extend the find method so >standard only non-hidden fields are found, and only when explicitly >calling find_unhidden you get them all :-) > >Jaap > >On 10/23/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote: > > >>So basically abstract the logic out of the controller and in to the >>model... I guess this is like the Depot example in the Rails book where >>an action called Salable_items is put in the Products model. This action >>does a find with a condition so only products that have the >>date_available field set in the past are returned. >> >>Cheers K >> >>Jaap Schreurs wrote: >> >> >> >>>Kris, >>> >>>Maybe you could implement a find_including_hidden and/or >>>find_without_hidden function in your model wich calls the find method. >>> >>>Jaap >>> >>>On 10/21/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote: >>> >>> >>> >>> >>>>Say I have a boolean field called hidden, which is set to true if I want >>>>to hide say a product or a task. >>>>Now I only want to hide the record for the customer side of the >>>>application and not admin side. >>>>So where do I put the logic that says either find all records or records >>>>where hidden <> 1? >>>> >>>>I could put it in the controller: >>>>@categories = Category.find(:first, :conditions => [''hidden <> 1 AND id >>>>= ?'', params[:id]]) >>>> >>>>but something tells me it should be in the model... >>>> >>>>Now I could put in the model so that any calls to find return only >>>>non-hidden fields. But then my admin side is blinded to hidden records >>>>and they are effectivly badly deleted instead of hidden. >>>> >>>>I''m keen to know how people go about this :) I''m sure there are maybe a >>>>few ways of doing this! >>>> >>>>Cheer K. >>>> >>>>_______________________________________________ >>>>Rails mailing list >>>>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>>http://lists.rubyonrails.org/mailman/listinfo/rails >>>> >>>> >>>> >>>> >>>> >>>_______________________________________________ >>>Rails mailing list >>>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>> >>> >>> >>> >>> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > >