Hi all,

I was just wondering if this is the intended behavior.  Here is my setup:

controller

  def index
    respond_to do |f|
      f.xml { render :xml => true }
      f.html { render :layout => :none }
    end
  end

In my views I have a file for each type

index.herb
index.xerb

The first request I send is cached and interferes with the other one.
For example, if I send an xml request first, followed by html, here is
what I see (those are just some debug statements I put in to follow
the code)

Request 1 "Accept: text/xml"

- "starting find_template, options are :"
   {:action=>"index", :ext=>"rxml,xerb,builder"}
- match on elsif action
   path is : /Users/dusty/nms/app/views/testing/index
- no cache, created glob
  glob is : /Users/dusty/nms/app/views/testing/index.{rxml,xerb,builder}
- searched Dir[glob].first and found
   found is : /Users/dusty/nms/app/views/testing/index.xerb
- finished find_template, template is:
   "/Users/dusty/nms/app/views/testing/index.xerb"

Request 2 "Accept: text/html"

- "starting find_template, options are :"
   {:action=>"index"}
- match on elsif action
   path is : /Users/dusty/nms/app/views/testing/index
- finish else, matched cached
   cached is : /Users/dusty/nms/app/views/testing/index.xerb
- finished find_template, template is:
   "/Users/dusty/nms/app/views/testing/index.xerb"

If I restart merb and reverse the order

Request 1 "Accept: text/html"

- "starting find_template, options are :"
   {:action=>"index"}
- match on elsif action
   path is : /Users/dusty/nms/app/views/testing/index
- no cache, created glob
  glob is :
/Users/dusty/nms/app/views/testing/index.{html.erb,jerb,herb,haml,mab,js.erb,xerb,rhtml,builder,rxml,erb}
- searched Dir[glob].first and found
   found is : /Users/dusty/nms/app/views/testing/index.herb
- finished find_template, template is:
  "/Users/dusty/nms/app/views/testing/index.herb"

Request 2 "Accept: text/xml"

- "starting find_template, options are :"
   {:action=>"index", :ext=>"rxml,xerb,builder"}
- match on elsif action
   path is : /Users/dusty/nms/app/views/testing/index
- finish else, matched cached
  cached is : /Users/dusty/nms/app/views/testing/index.herb
- finished find_template, template is:
   "/Users/dusty/nms/app/views/testing/index.herb"

* this caught me by suprise, it searched for layouts too.

- "starting find_template, options are :"
   {:layout=>"testing"}
- match on elsif _layout
   path is : /Users/dusty/nms/app/views/layout/testing
- no cache, created glob
   glob is : 
/Users/dusty/nms/app/views/layout/testing.{html.erb,jerb,herb,haml,mab,js.erb,xerb,rhtml,builder,rxml,erb}
- failed Dir[glob].first and set @merb_unmatched:
   glob is : 
/Users/dusty/nms/app/views/layout/testing.{html.erb,jerb,herb,haml,mab,js.erb,xerb,rhtml,builder,rxml,erb}
- "starting find_template, options are :"
   {:layout=>:application}
- match on elsif _layout
   path is : /Users/dusty/nms/app/views/layout/application
- no cache, created glob
   glob is : 
/Users/dusty/nms/app/views/layout/application.{html.erb,jerb,herb,haml,mab,js.erb,xerb,rhtml,builder,rxml,erb}
- searched Dir[glob].first and found
   found is : /Users/dusty/nms/app/views/layout/application.html.erb

So, I suppose that the EASY workaround is to rename my xml template to
something like index_xml.xerb and then call it like:

render :xml => :index_xml

I was just wondering if that was the intended behavior, that's all.
The documentation threw me off for a second there because of this
line.

    #   render :xml => true
    #   render :xml => true, :action => "buffalo"
    #
    # Renders the buffalo.xerb template for the current controller.

So, render :xml => true, does work out of the box.  But, if you have
an another view with the same name before the extension, they
interfere with eachother.  It this is intended, then I'll supply a
little documentation patch to warn about that.

Thanks
Dusty Doris
_______________________________________________
Merb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/merb-devel

Reply via email to