I like the &quot;provides :xml&quot; or &quot;publish :xml&quot; syntax with the usual options (:only, :except, :if etc.).<div>that way you can manage all the response type from one location.</div><div><br>
</div><div>Sometimes respond_to case-style works well when each response gets something different but many times that&#39;s not the case and when it doesn&#39;t, it sucks.</div><div><br>&nbsp;</div>
<div>In rails I created a helper that looks at the format param so that I can do something like&nbsp;render :xml =&gt; @user.to_xml if requested_as(:xml)&nbsp;</div><div><div><br>&nbsp;</div><div>I personally think that the guys from make_resourceful got it almost right.&nbsp;
</div><div>One thing that I think it&#39;s smart is not to use the &quot;def&quot; keyword. Since actions are more than just methods. You could do something more clever. build :index{ something here } that would either define multiple methods or return objects.
</div><div><br>&nbsp;</div><div>You can still make it work with just methods, maybe something like this</div><div><br>&nbsp;</div><div><div>class User &lt; Application
</div><div><br>&nbsp;</div><div>&nbsp;&nbsp;#&nbsp;sets default responses and returns values</div><div>&nbsp;&nbsp;publish :html, :xml, :json, :only =&gt; [:show, :edit, :destroy], :returns =&gt; {:user =&gt; [:login, :email], :head =&gt; &quot;success&quot;}
</div><div><br>&nbsp;</div><div>&nbsp;&nbsp;# run filters conditionally to request type</div><div>&nbsp;&nbsp;before :index, :show, :do =&gt; [:get_user, :increase_counter] if requested_as(:html, :xml)</div><div><br>
</div><div>&nbsp;&nbsp;# custom responses by request types</div><div>&nbsp;&nbsp;responses_for [:index, :destroy] =&gt; {:xml =&gt; :user,</div><div><span style="white-space:pre">                                                </span>&nbsp;&nbsp; &nbsp;&nbsp;:html =&gt; render(&quot;
index.erb&quot;)}</div><div><span style="white-space:pre">                        </span>&nbsp;</div><div>&nbsp;&nbsp;def index</div><div><span style="white-space:pre">        </span>#only code in common with all the responses here.
</div><div>&nbsp;&nbsp;end</div><div><br>&nbsp;</div><div>end</div></div><div><br>&nbsp;</div><div>Just trowing some ideas out there.</div><div>Diego</div><div><br>
</div><div>I imagine you could pass reponses_for an array of hashes too.</div><div>responses_for :show =&gt; {:xml =&gt; :user}, :destroy =&gt; {:xml =&gt; {:head =&gt; &quot;success&quot;}}<br>responses_for :edit =&gt; {:xml =&gt; 
Proc.new{ render &quot;index.erb&quot;}}</div><div><span class="e" id="q_115291a6e8dfacf5_1"><div><br><div><span class="gmail_quote">On 9/20/07, <b class="gmail_sendername">Ezra Zygmuntowicz</b> &lt;<a href="mailto:ez@engineyard.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
ez@engineyard.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Merb controllers cannot be modules because modules are not<br>instantiatable. The way merb&#39;s thread safety works is by
<br>instantiating a new controller object for each new request/thread.<br><br>-Ezra<br><br>On Sep 20, 2007, at 1:13 PM, ry dahl wrote:<br><br>&gt; On 9/20/07, John Weir &lt;<a href="mailto:john@smokinggun.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
john@smokinggun.com
</a>&gt; wrote:<br>&gt;&gt; how would filters and common methods work?<br>&gt;<br>&gt; one way this could be done is by attaching a filters as class methods<br>&gt; to the actions. for example<br>&gt;<br>&gt; module Controllers::Products
<br>&gt;&nbsp;&nbsp; before Index, Show do |request|<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; raise Unauthorized unless request.session[:user].admin?<br>&gt;&nbsp;&nbsp; end<br>&gt;&nbsp;&nbsp; ...<br>&gt; end<br>&gt;<br>&gt; would take the block argument, add do<br>&gt;&nbsp;&nbsp; Index.class_eval

 { @@before_filter = block }<br>&gt; for both Index and Show. At the time of request, the dispatcher could<br>&gt; call that block before instantiating the action.<br>&gt;<br>&gt; this is just an example for entertaining the idea - not a proposal - i
<br>&gt; haven&#39;t thought all the way through it<br>&gt;<br>&gt;<br>&gt;&gt;&gt; For example,<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; module Controllers::Products<br>&gt;&gt;&gt;&nbsp;&nbsp; class Index &lt; GetAction<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; def initialize(params)
<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @products = Product.paginate(params[:page] || 1)<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; def response_json<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @products.to_json<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;&gt;&gt;
<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; def response_html<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; render &#39;products/index.erb&#39;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;&gt;&gt;&nbsp;&nbsp; end<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&nbsp;&nbsp; class Show &lt; GetAction<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; extra_route &#39;:id&#39;
<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; def initialize(params)<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @products = Product.find(params[:id])<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; def response_html<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; render &#39;products/show.erb&#39;
<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;&gt;&gt;&nbsp;&nbsp; end<br>&gt;&gt;&gt; end<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; &lt;%= link_to &#39;Products&#39;, Controllers::Products::Index.url %&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; On 9/20/07, ry dahl &lt;
<a href="mailto:ry@tinyclouds.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">ry@tinyclouds.org</a>&gt; wrote:<br>&gt;&gt;&gt;&gt; Sometimes it seems like actions deserve to be their own objects: we
<br>&gt;&gt;&gt;&gt; map routes to them, we&#39;d like to know what parameters they
<br>&gt;&gt;&gt;&gt; expect, we<br>&gt;&gt;&gt;&gt; want to say which http methods they accept, we assign them<br>&gt;&gt;&gt;&gt; before/after filters, and we even hold collections of them<br>&gt;&gt;&gt;&gt; (Controller.callable_actions

). This responds_to issue is another<br>&gt;&gt;&gt;&gt; example of how we&#39;d like to treat actions as objects. We would like<br>&gt;&gt;&gt;&gt; for the controller to look at the request, determine which<br>&gt;&gt;&gt;&gt; format to
<br>&gt;&gt;&gt;&gt; send, and then simply call my_action.render_json or<br>&gt;&gt;&gt;&gt; my_action.render_html. Simultaneously, our controllers are not very<br>&gt;&gt;&gt;&gt; class like. They are basically instantiate them only to call the
<br>&gt;&gt;&gt;&gt; action. Changing the Controller class into a module would not be so<br>&gt;&gt;&gt;&gt; hard in the current Merb - they are (more or less) just containers<br>&gt;&gt;&gt;&gt; for<br>&gt;&gt;&gt;&gt; actions.
<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Has anyone else been having these thoughts?<br>&gt;&gt;&gt;&gt;<br>&gt; _______________________________________________<br>&gt; Merb-devel mailing list<br>&gt; <a href="mailto:Merb-devel@rubyforge.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

Merb-devel@rubyforge.org</a><br>&gt; <a href="http://rubyforge.org/mailman" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://rubyforge.org/mailman</a>/listinfo/merb-devel<br><br>-- Ezra Zygmuntowicz
<br>-- Founder &amp; Ruby Hacker<br>-- <a href="mailto:ez@engineyard.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
ez@engineyard.com</a><br>-- Engine Yard, Serious Rails Hosting<br>-- (866) 518-YARD (9273)<br><br><br>_______________________________________________<br>Merb-devel mailing list<br><a href="mailto:Merb-devel@rubyforge.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

Merb-devel@rubyforge.org</a><br><a href="http://rubyforge.org/mailman" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://rubyforge.org/mailman</a>/listinfo/merb-devel<br></blockquote></div><br>
&nbsp;</div></span></div></div>