From coder at montx.com Sun Oct 3 07:21:12 2010 From: coder at montx.com (Raimon Fernandez) Date: Sun, 3 Oct 2010 13:21:12 +0200 Subject: Using filters In-Reply-To: <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> Message-ID: Hi, I'm trying to use filters in my Camping App, but at this moment they are not working ... I've found some presentation by Jeremy McAnally (http://slideshow.rubyforge.org/camping.html#1) At the end, appears a Library that makes our life easier, but I can't find this library. Also, this presentation is from 2007 and we are now in 2011, so maybe Camping can handle those filters in an easy way. I use them in Rails but here I'm getting always ./list.rb:278: uninitialized constant List::Filters (NameError) Basically what I want to do is before each controller, check if there are some input variables in the post, and proceed if they are OK or send an error page, well, preferably a an error status in the header. thanks in advance, regards, r. ************************************************************************************************************ Here is what says about Kindling: Kindling ? A new library by me that takes the top 5-10 ?Railsisms? and lets you use them in Camping ? Currently supports? ? Easy before/after filters ? Static file download/upload ? Easy addition of template handlers, with default support for ERb ************************************************************************************************************ From a at creativepony.com Sun Oct 3 10:02:02 2010 From: a at creativepony.com (Jenna Fox) Date: Mon, 4 Oct 2010 01:02:02 +1100 Subject: Using filters In-Reply-To: References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> Message-ID: Maybe it'd work if you set your clock correctly? Worth a shot. ? Jenna On 03/10/2010, at 10:21 PM, Raimon Fernandez wrote: > Hi, > > > I'm trying to use filters in my Camping App, but at this moment they are not working ... > > I've found some presentation by Jeremy McAnally (http://slideshow.rubyforge.org/camping.html#1) > > At the end, appears a Library that makes our life easier, but I can't find this library. > > Also, this presentation is from 2007 and we are now in 2011, so maybe Camping can handle those filters in an easy way. > > I use them in Rails but here I'm getting always ./list.rb:278: uninitialized constant List::Filters (NameError) > > Basically what I want to do is before each controller, check if there are some input variables in the post, and proceed if they are OK or send an error page, well, preferably a an error status in the header. > > thanks in advance, > > regards, > > r. > > ************************************************************************************************************ > > Here is what says about Kindling: > > Kindling > > ? A new library by me that takes the top 5-10 ?Railsisms? and lets you use them in Camping > ? Currently supports? > ? Easy before/after filters > ? Static file download/upload > ? Easy addition of template handlers, with default support for ERb > > ************************************************************************************************************ > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list From ruby at monnet-usa.com Sun Oct 3 10:30:36 2010 From: ruby at monnet-usa.com (Philippe Monnet) Date: Sun, 03 Oct 2010 08:30:36 -0600 Subject: Using filters In-Reply-To: References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> Message-ID: <4CA8938C.1000204@monnet-usa.com> Hi Raimon, Take a look at one of my blog posts on using Camping and OAuth, there a section regarding the use of filters: http://blog.monnet-usa.com/?p=293#caoatodoa I had packaged Magnus' filtering_camping library as a gem. You can also see how I use filters in the Camping OAuth plugin: http://github.com/techarch/camping-oauth See |To implement filtering: | 1) |gem install filtering_camping 2) in your main Camping module add: include CampingFilters | 3) still in your main module add your global filters: before :all do | x | Camping::Models::Base.logger.debug "[before] filter on #{x.inspect}" end after :all do end 4) add your controller specific filters # when targeting a single controller before :MyController1 do #your filter logic end after :MyController1 do #your filter logic end # when targeting multiple controllers use an array before [:MyController2, MyController3] do #your filter logic end after [:MyController2, MyController3] do #your filter logic end Note you can also use a lambda: myblock1 = lambda { Camping::Models::Base.logger.debug "hello - before (Index)" } before :Index , &myblock1 One of these days I'll write a post on that. ;-) Philippe (@techarch) On 10/3/2010 5:21 AM, Raimon Fernandez wrote: > Hi, > > > I'm trying to use filters in my Camping App, but at this moment they are not working ... > > I've found some presentation by Jeremy McAnally (http://slideshow.rubyforge.org/camping.html#1) > > At the end, appears a Library that makes our life easier, but I can't find this library. > > Also, this presentation is from 2007 and we are now in 2011, so maybe Camping can handle those filters in an easy way. > > I use them in Rails but here I'm getting always ./list.rb:278: uninitialized constant List::Filters (NameError) > > Basically what I want to do is before each controller, check if there are some input variables in the post, and proceed if they are OK or send an error page, well, preferably a an error status in the header. > > thanks in advance, > > regards, > > r. > > ************************************************************************************************************ > > Here is what says about Kindling: > > Kindling > > ? A new library by me that takes the top 5-10 ?Railsisms? and lets you use them in Camping > ? Currently supports? > ? Easy before/after filters > ? Static file download/upload > ? Easy addition of template handlers, with default support for ERb > > ************************************************************************************************************ > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From coder at montx.com Sun Oct 3 10:42:07 2010 From: coder at montx.com (Raimon Fernandez) Date: Sun, 3 Oct 2010 16:42:07 +0200 Subject: Using filters In-Reply-To: References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> Message-ID: <8DD4F66E-8E18-46EE-BE44-A175271CC289@montx.com> On 3oct, 2010, at 16:02 , Jenna Fox wrote: > Maybe it'd work if you set your clock correctly? > > Worth a shot. I'm a programmer of the future ... :-))) back to reality, we are in 2010 ... r. > > ? > Jenna > > > On 03/10/2010, at 10:21 PM, Raimon Fernandez wrote: > >> Hi, >> >> >> I'm trying to use filters in my Camping App, but at this moment they are not working ... >> >> I've found some presentation by Jeremy McAnally (http://slideshow.rubyforge.org/camping.html#1) >> >> At the end, appears a Library that makes our life easier, but I can't find this library. >> >> Also, this presentation is from 2007 and we are now in 2011, so maybe Camping can handle those filters in an easy way. >> >> I use them in Rails but here I'm getting always ./list.rb:278: uninitialized constant List::Filters (NameError) >> >> Basically what I want to do is before each controller, check if there are some input variables in the post, and proceed if they are OK or send an error page, well, preferably a an error status in the header. >> >> thanks in advance, >> >> regards, >> >> r. >> >> ************************************************************************************************************ >> >> Here is what says about Kindling: >> >> Kindling >> >> ? A new library by me that takes the top 5-10 ?Railsisms? and lets you use them in Camping >> ? Currently supports? >> ? Easy before/after filters >> ? Static file download/upload >> ? Easy addition of template handlers, with default support for ERb >> >> ************************************************************************************************************ >> _______________________________________________ >> Camping-list mailing list >> Camping-list at rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > From coder at montx.com Sun Oct 3 10:45:59 2010 From: coder at montx.com (Raimon Fernandez) Date: Sun, 3 Oct 2010 16:45:59 +0200 Subject: Using filters In-Reply-To: References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> Message-ID: <7EBDA11C-3E5D-4F11-8327-4D069CF0A77C@montx.com> Hi, Finally I could remember the great Blog camping, where are some filters that do what I want ... thanks, r. On 3oct, 2010, at 13:21 , Raimon Fernandez wrote: > Hi, > > > I'm trying to use filters in my Camping App, but at this moment they are not working ... > > I've found some presentation by Jeremy McAnally (http://slideshow.rubyforge.org/camping.html#1) > > At the end, appears a Library that makes our life easier, but I can't find this library. > > Also, this presentation is from 2007 and we are now in 2011, so maybe Camping can handle those filters in an easy way. > > I use them in Rails but here I'm getting always ./list.rb:278: uninitialized constant List::Filters (NameError) > > Basically what I want to do is before each controller, check if there are some input variables in the post, and proceed if they are OK or send an error page, well, preferably a an error status in the header. > > thanks in advance, > > regards, > > r. > > ************************************************************************************************************ > > Here is what says about Kindling: > > Kindling > > ? A new library by me that takes the top 5-10 ?Railsisms? and lets you use them in Camping > ? Currently supports? > ? Easy before/after filters > ? Static file download/upload > ? Easy addition of template handlers, with default support for ERb > > ************************************************************************************************************ > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > From coder at montx.com Sun Oct 3 11:35:00 2010 From: coder at montx.com (Raimon Fernandez) Date: Sun, 3 Oct 2010 17:35:00 +0200 Subject: Using filters In-Reply-To: <4CA8938C.1000204@monnet-usa.com> References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> <4CA8938C.1000204@monnet-usa.com> Message-ID: <6499BB49-1312-4D3E-B3A9-99FFF3BF48E7@montx.com> Hi Philippe, Thanks for your long explain, I'll have a look to your blog post also ! regards, r. On 3oct, 2010, at 16:30 , Philippe Monnet wrote: > Hi Raimon, > > Take a look at one of my blog posts on using Camping and OAuth, there a section regarding the use of filters: http://blog.monnet-usa.com/?p=293#caoatodoa > I had packaged Magnus' filtering_camping library as a gem. > You can also see how I use filters in the Camping OAuth plugin: http://github.com/techarch/camping-oauth > See > > To implement filtering: > 1) gem install filtering_camping > > 2) in your main Camping module add: > include CampingFilters > > 3) still in your main module add your global filters: > > before :all do | x | > Camping::Models::Base.logger.debug "[before] filter on #{x.inspect}" > end > > after :all do > end > > 4) add your controller specific filters > > # when targeting a single controller > before :MyController1 do > #your filter logic > end > > after :MyController1 do > #your filter logic > end > > # when targeting multiple controllers use an array > before [:MyController2, MyController3] do > #your filter logic > end > > after [:MyController2, MyController3] do > #your filter logic > end > > Note you can also use a lambda: > > myblock1 = lambda { Camping::Models::Base.logger.debug "hello - before (Index)" } > before :Index , &myblock1 > > One of these days I'll write a post on that. ;-) > > Philippe (@techarch) > > On 10/3/2010 5:21 AM, Raimon Fernandez wrote: >> >> Hi, >> >> >> I'm trying to use filters in my Camping App, but at this moment they are not working ... >> >> I've found some presentation by Jeremy McAnally (http://slideshow.rubyforge.org/camping.html#1) >> >> At the end, appears a Library that makes our life easier, but I can't find this library. >> >> Also, this presentation is from 2007 and we are now in 2011, so maybe Camping can handle those filters in an easy way. >> >> I use them in Rails but here I'm getting always ./list.rb:278: uninitialized constant List::Filters (NameError) >> >> Basically what I want to do is before each controller, check if there are some input variables in the post, and proceed if they are OK or send an error page, well, preferably a an error status in the header. >> >> thanks in advance, >> >> regards, >> >> r. >> >> ************************************************************************************************************ >> >> Here is what says about Kindling: >> >> Kindling >> >> ? A new library by me that takes the top 5-10 ?Railsisms? and lets you use them in Camping >> ? Currently supports? >> ? Easy before/after filters >> ? Static file download/upload >> ? Easy addition of template handlers, with default support for ERb >> >> ************************************************************************************************************ >> _______________________________________________ >> Camping-list mailing list >> Camping-list at rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list >> > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From coder at montx.com Sun Oct 3 12:09:23 2010 From: coder at montx.com (Raimon Fernandez) Date: Sun, 3 Oct 2010 18:09:23 +0200 Subject: Forcing a Response Status-Code of 40x In-Reply-To: <6499BB49-1312-4D3E-B3A9-99FFF3BF48E7@montx.com> References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> <4CA8938C.1000204@monnet-usa.com> <6499BB49-1312-4D3E-B3A9-99FFF3BF48E7@montx.com> Message-ID: <8ACA078C-8E7E-4B00-B495-335026BC5F0E@montx.com> Hi again, I'm trying to force a different Response Status-Code when some situations occur. Once again, in Rails I just use the :status => 404 and that's all ... Here, I suppose I must use the @headers[] but I'm always getting the 200 Status OK. I'm not sure wich name exactly the header must be, as in Internet there are lots of options and none of them is giving me a 404 or whatever code I use, I'm always getting the 200. If I force a bad url, camping returns the famouse Camping problem with a 404 status code, I want to force this code. How can I do that ? ... @headers["Content-Type"] = "text/xml" # none of them are working ... @headers["HTTP/1.0"] = "404" @headers["Status"] = "404" @headers["Response"] = "404" @headers["Status-Code"] = "404" maybe I have to use a different option in camping ? thanks again, regards, r. From judofyr at gmail.com Sun Oct 3 12:21:41 2010 From: judofyr at gmail.com (Magnus Holm) Date: Sun, 3 Oct 2010 18:21:41 +0200 Subject: Forcing a Response Status-Code of 40x In-Reply-To: <8ACA078C-8E7E-4B00-B495-335026BC5F0E@montx.com> References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> <4CA8938C.1000204@monnet-usa.com> <6499BB49-1312-4D3E-B3A9-99FFF3BF48E7@montx.com> <8ACA078C-8E7E-4B00-B495-335026BC5F0E@montx.com> Message-ID: @status = 404 // Magnus Holm On Sun, Oct 3, 2010 at 18:09, Raimon Fernandez wrote: > Hi again, > > I'm trying to force a different Response Status-Code when some situations > occur. > > Once again, in Rails I just use the :status => 404 and that's all ... > > Here, I suppose I must use the @headers[] but I'm always getting the 200 > Status OK. > > I'm not sure wich name exactly the header must be, as in Internet there are > lots of options and none of them is giving me a 404 or whatever code I use, > I'm always getting the 200. > > If I force a bad url, camping returns the famouse Camping problem with a > 404 status code, I want to force this code. > > How can I do that ? > > ... > > @headers["Content-Type"] = "text/xml" > > # none of them are working ... > > @headers["HTTP/1.0"] = "404" > @headers["Status"] = "404" > @headers["Response"] = "404" > @headers["Status-Code"] = "404" > > maybe I have to use a different option in camping ? > > thanks again, > > regards, > > r. > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From john.beppu at gmail.com Sun Oct 3 12:22:17 2010 From: john.beppu at gmail.com (John Beppu) Date: Sun, 3 Oct 2010 09:22:17 -0700 Subject: Forcing a Response Status-Code of 40x In-Reply-To: <8ACA078C-8E7E-4B00-B495-335026BC5F0E@montx.com> References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> <4CA8938C.1000204@monnet-usa.com> <6499BB49-1312-4D3E-B3A9-99FFF3BF48E7@montx.com> <8ACA078C-8E7E-4B00-B495-335026BC5F0E@montx.com> Message-ID: @status = 404 On Sun, Oct 3, 2010 at 9:09 AM, Raimon Fernandez wrote: > Hi again, > > I'm trying to force a different Response Status-Code when some situations > occur. > > Once again, in Rails I just use the :status => 404 and that's all ... > > Here, I suppose I must use the @headers[] but I'm always getting the 200 > Status OK. > > I'm not sure wich name exactly the header must be, as in Internet there are > lots of options and none of them is giving me a 404 or whatever code I use, > I'm always getting the 200. > > If I force a bad url, camping returns the famouse Camping problem with a > 404 status code, I want to force this code. > > How can I do that ? > > ... > > @headers["Content-Type"] = "text/xml" > > # none of them are working ... > > @headers["HTTP/1.0"] = "404" > @headers["Status"] = "404" > @headers["Response"] = "404" > @headers["Status-Code"] = "404" > > maybe I have to use a different option in camping ? > > thanks again, > > regards, > > r. > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From coder at montx.com Sun Oct 3 16:47:37 2010 From: coder at montx.com (Raimon Fernandez) Date: Sun, 3 Oct 2010 22:47:37 +0200 Subject: Forcing a Response Status-Code of 40x In-Reply-To: References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> <4CA8938C.1000204@monnet-usa.com> <6499BB49-1312-4D3E-B3A9-99FFF3BF48E7@montx.com> <8ACA078C-8E7E-4B00-B495-335026BC5F0E@montx.com> Message-ID: <68259A9C-84CE-4C6F-8ED2-0A2129C67162@montx.com> Thanks John & Magnus, Where I can find more info about those little magic ???? :-) Also, I was calling from the wrong place, in a helper it is not working, but works if I call from a Controller. thanks again, regards, r. On 3oct, 2010, at 18:22 , John Beppu wrote: > @status = 404 On 3oct, 2010, at 18:21 , Magnus Holm wrote: > @status = 404 From judofyr at gmail.com Sun Oct 3 16:54:22 2010 From: judofyr at gmail.com (Magnus Holm) Date: Sun, 3 Oct 2010 22:54:22 +0200 Subject: Forcing a Response Status-Code of 40x In-Reply-To: <68259A9C-84CE-4C6F-8ED2-0A2129C67162@montx.com> References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> <4CA8938C.1000204@monnet-usa.com> <6499BB49-1312-4D3E-B3A9-99FFF3BF48E7@montx.com> <8ACA078C-8E7E-4B00-B495-335026BC5F0E@montx.com> <68259A9C-84CE-4C6F-8ED2-0A2129C67162@montx.com> Message-ID: There's some info about the request/response here: http://camping.rubyforge.org/api.html#class-Camping-Controllers // Magnus Holm On Sun, Oct 3, 2010 at 22:47, Raimon Fernandez wrote: > Thanks John & Magnus, > > > Where I can find more info about those little magic ???? > > :-) > > Also, I was calling from the wrong place, in a helper it is not working, > but works if I call from a Controller. > > thanks again, > > regards, > > r. > > > On 3oct, 2010, at 18:22 , John Beppu wrote: > > > @status = 404 > > > On 3oct, 2010, at 18:21 , Magnus Holm wrote: > > > @status = 404 > > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From coder at montx.com Sun Oct 3 17:09:47 2010 From: coder at montx.com (Raimon Fernandez) Date: Sun, 3 Oct 2010 23:09:47 +0200 Subject: Forcing a Response Status-Code of 40x In-Reply-To: References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> <4CA8938C.1000204@monnet-usa.com> <6499BB49-1312-4D3E-B3A9-99FFF3BF48E7@montx.com> <8ACA078C-8E7E-4B00-B495-335026BC5F0E@montx.com> <68259A9C-84CE-4C6F-8ED2-0A2129C67162@montx.com> Message-ID: <2926A944-A9EE-47BE-ACEF-EF6144828B31@montx.com> oooouuuccccchhhhh !!!!!!!! it's there !!!!!! I've read it twice before posting here ..... :-( thanks again, r. The Response: You can change these variables to your needs: ? @status is the HTTP status (defaults to 200) ? @headers is a hash with the headers ? @body is the body (a string or something which responds to each) ? Any changes in @cookies and @state will also be sent to the client On 3oct, 2010, at 22:54 , Magnus Holm wrote: > There's some info about the request/response here: http://camping.rubyforge.org/api.html#class-Camping-Controllers > > // Magnus Holm > > > On Sun, Oct 3, 2010 at 22:47, Raimon Fernandez wrote: > Thanks John & Magnus, > > > Where I can find more info about those little magic ???? > > :-) > > Also, I was calling from the wrong place, in a helper it is not working, but works if I call from a Controller. > > thanks again, > > regards, > > r. > > > On 3oct, 2010, at 18:22 , John Beppu wrote: > > > @status = 404 > > > On 3oct, 2010, at 18:21 , Magnus Holm wrote: > > > @status = 404 > > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list From coder at montx.com Mon Oct 4 05:39:44 2010 From: coder at montx.com (Raimon Fernandez) Date: Mon, 4 Oct 2010 11:39:44 +0200 Subject: Using filters In-Reply-To: <4CA8938C.1000204@monnet-usa.com> References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> <4CA8938C.1000204@monnet-usa.com> Message-ID: <72E547D9-F4F4-45D0-A143-30E58A96553D@montx.com> Hi, In my main Camping module I'm including the views: include Views # We include the Views module so we can call them as methods. My controllers call those views directly, as I'm generating always .xml responses, never .html If I remove the Include Views the filters work as expected, but not my Controllers that can't call directly the views Why it's not working if I just include the views ? Also , I noted that some examples have all de models nested inside the main Camping Model, and some others are defined outside it. My problem is the same no matter wich approach I take. Here is some code: require 'camping' require 'ostruct' require 'builder' require 'filtering_camping' Camping.goes :List module List include CampingFilters before [:ResumeGroupedByDevice, :ResumeGroupedl] do @device = Device.find_by_device_id(input.device_uuid) end include Views # We include the Views module so we can call them as methods. module List::Controllers ... class Device < Base end ... module List::Controllers ... class ResumeGroupedByDevice < R '/people/resume_by_device' def post @resume = Person.find(:all,xxxxxxxxxxxx) xml :people_resume_by_device end end ... module List::Helpers def xml(name) # We'll need to send this as text/xml @headers["Content-Type"] = "text/xml" result = String.new # The builder takes a `target` where the XML will end up builder = Builder::XmlMarkup.new(:target => result, :indent => 2) # Generates a builder.instruct! # Calls the method you sent in, passing in the builder as an argument send(name, builder) # Return the restult result end ... module List::Views def people_resume_by_device(xml) xml.groups(:found => @resume.size) do @resume.each do |element| xml.group do xml.id(0) # future use! xml.device_name(element.device_name) xml.count(element.count) end end end end thanks .... r. On 3oct, 2010, at 16:30 , Philippe Monnet wrote: > Take a look at one of my blog posts on using Camping and OAuth, there a section regarding the use of filters: http://blog.monnet-usa.com/?p=293#caoatodoa > I had packaged Magnus' filtering_camping library as a gem. > You can also see how I use filters in the Camping OAuth plugin: http://github.com/techarch/camping-oauth > See > > To implement filtering: > 1) gem install filtering_camping > > 2) in your main Camping module add: > include CampingFilters > > 3) still in your main module add your global filters: > > before :all do | x | > Camping::Models::Base.logger.debug "[before] filter on #{x.inspect}" > end > > after :all do > end > > 4) add your controller specific filters > > # when targeting a single controller > before :MyController1 do > #your filter logic > end > > after :MyController1 do > #your filter logic > end > > # when targeting multiple controllers use an array > before [:MyController2, MyController3] do > #your filter logic > end > > after [:MyController2, MyController3] do > #your filter logic > end -------------- next part -------------- An HTML attachment was scrubbed... URL: From coder at montx.com Mon Oct 4 06:48:17 2010 From: coder at montx.com (Raimon Fernandez) Date: Mon, 4 Oct 2010 12:48:17 +0200 Subject: Using filters In-Reply-To: <72E547D9-F4F4-45D0-A143-30E58A96553D@montx.com> References: <58F1EA48-1263-4005-838E-CA65DFD04E01@montx.com> <5941C24F-7662-44E6-91AC-2A5FCDBC2FD9@montx.com> <2FFA15C4-CC71-4360-82A2-A496690362AA@montx.com> <4CA8938C.1000204@monnet-usa.com> <72E547D9-F4F4-45D0-A143-30E58A96553D@montx.com> Message-ID: <088CEE02-9D63-432D-BD07-D5D16010F4D8@montx.com> Ok, solved, but I would like to know why: This works and the filers execute: include Views # We include the Views module so we can call them as methods. include CampingFilters This DON'T work, filters never execute include CampingFilters include Views # We include the Views module so we can call them as methods. There is some precedence in order ? thanks, r. On 4oct, 2010, at 11:39 , Raimon Fernandez wrote: > Hi, > > > In my main Camping module I'm including the views: > > include Views # We include the Views module so we can call them as methods. > > > My controllers call those views directly, as I'm generating always .xml responses, never .html > > If I remove the Include Views the filters work as expected, but not my Controllers that can't call directly the views > > Why it's not working if I just include the views ? > > Also , I noted that some examples have all de models nested inside the main Camping Model, and some others are defined outside it. > > My problem is the same no matter wich approach I take. > > Here is some code: > > > require 'camping' > require 'ostruct' > require 'builder' > require 'filtering_camping' > > Camping.goes :List > > module List > > include CampingFilters > > > > before [:ResumeGroupedByDevice, :ResumeGroupedl] do > @device = Device.find_by_device_id(input.device_uuid) > end > > include Views # We include the Views module so we can call them as methods. > > module List::Controllers > > ... > > class Device < Base > end > > ... > > > module List::Controllers > > ... > > class ResumeGroupedByDevice < R '/people/resume_by_device' > > def post > @resume = Person.find(:all,xxxxxxxxxxxx) > xml :people_resume_by_device > end > > end > > ... > > module List::Helpers > def xml(name) > # We'll need to send this as text/xml > @headers["Content-Type"] = "text/xml" > result = String.new > # The builder takes a `target` where the XML will end up > builder = Builder::XmlMarkup.new(:target => result, :indent => 2) > # Generates a > builder.instruct! > # Calls the method you sent in, passing in the builder as an argument > send(name, builder) > # Return the restult > result > end > > ... > > > module List::Views > > def people_resume_by_device(xml) > xml.groups(:found => @resume.size) do > @resume.each do |element| > xml.group do > xml.id(0) # future use! > xml.device_name(element.device_name) > xml.count(element.count) > end > end > end > end > > > > thanks .... > > r. > > > > > On 3oct, 2010, at 16:30 , Philippe Monnet wrote: > >> Take a look at one of my blog posts on using Camping and OAuth, there a section regarding the use of filters: http://blog.monnet-usa.com/?p=293#caoatodoa >> I had packaged Magnus' filtering_camping library as a gem. >> You can also see how I use filters in the Camping OAuth plugin: http://github.com/techarch/camping-oauth >> See >> >> To implement filtering: >> 1) gem install filtering_camping >> >> 2) in your main Camping module add: >> include CampingFilters >> >> 3) still in your main module add your global filters: >> >> before :all do | x | >> Camping::Models::Base.logger.debug "[before] filter on #{x.inspect}" >> end >> >> after :all do >> end >> >> 4) add your controller specific filters >> >> # when targeting a single controller >> before :MyController1 do >> #your filter logic >> end >> >> after :MyController1 do >> #your filter logic >> end >> >> # when targeting multiple controllers use an array >> before [:MyController2, MyController3] do >> #your filter logic >> end >> >> after [:MyController2, MyController3] do >> #your filter logic >> end > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list -------------- next part -------------- An HTML attachment was scrubbed... URL: