Reputation: 699
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'
Upvotes: 0
Views: 471
Reputation: 472
I'm not sure it answers your question but using render :text => @foobar.to_json does wonders in some cases.
Upvotes: 2
Reputation: 410922
No -- you specify what view template to render in the controller action.
Upvotes: 1