0

Part 1:

I have a call to layout(:default){|path,wish| wish !~ /rss|atom|json/} but requests to /foo/bar.json seem to think wish is html and uses the layout anyway. How can I fix this?

Part 2:

I want to route /path/to/file.ext so that it calls the method to on the controller mapped to /path and uses ext when formulating the return. Is there a better (more elegant) way to do this than passing the 'file.ext' to the to method, parsing it, and doing cases? This question would have been more succinct if I had written, how does one do REST with Ramaze? There appears to be a Google Groups answer to this one, but I can't access it for some reason.

Loyal Tingley
  • 910
  • 1
  • 8
  • 20

1 Answers1

1
class ToController < Controller

  map '/path/to'
  provide( :json, :type => "application/json") { |action, val| val.to_json } 

  def bar
    @barInfo = {name: "Fonzie's", poison: "milk"}
  end

end

This controller returns plain JSON when you request /path/to/bar.json and uses the layout+view wrapping when you request /path/to/bar (Ramaze has no default layout setting, the layout in this example comes from the Controller parent class).

Arnaud Meuret
  • 985
  • 8
  • 26
  • Works perfectly! I can take out the horrible kludge I had in place now :) – Loyal Tingley Nov 16 '10 at 16:51
  • Cool. Ramaze routing can be confusing but usually there is a nice way to fill any particular need you may have. The template resolution system is very flexible too, and confusing sometimes. – Arnaud Meuret Nov 17 '10 at 13:49