views:

42

answers:

2

I would like to create one .erb file to be the output for a number of tiny actions that are just returning JSON. So with routes similar to:

map.json 'contacts_json', :controller => 'contacts', :action => 'get_json' 
map.json 'cal_json', :controller => 'calendar', :action => 'get_json'
...

but this requires I create a contacts erb, and a calendar erb so on and so forth. Is there a way to explicitly tell them to use a json erb? Something like:

map.json 'contacts_json', :controller => 'contacts', :action => 'get_json', :view => 'layouts/json.html.erb'
+1  A: 

No -- you specify what view template to render in the controller action.

mipadi
+2  A: 

I'm not sure it answers your question but using render :text => @foobar.to_json does wonders in some cases.

evaneykelen
Exactly what I was looking for. Thank you.
Felix