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 <?xml version="1.0" encoding="UTF-8" ?> > 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@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list
_______________________________________________ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list