简体   繁体   中英

How do I use HAML to render JSON views in Rails3?

I'd like to have my controller render json views, as .json.haml ... is this possible? What is the syntax like? Or would I need to use something else for JSON templating? such as http://inem.github.com/tequila.html ?

HAML is intented for use to generate HTML markup.

If you need to render json, just call render passing :json as an option within your controller:

render :json => my_object

Or if you have a more complex data structure and/or require more flexibility try JSON Builder , it's a template engine for JSON, similar to the XML builder provided in Rails.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM