This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contacts::ApplicationController | |
respond_to :json, :html | |
def index | |
respond_with Contacts.all | |
end | |
end |
Given the above controller, if you just use .haml instead of .html.haml every response will be rendered using that .haml template.
Initially I had created app/views/contacts/index.haml for responding to html requests.
After I changed 'repond_to :html' to 'respond_to :html, :json' -- I was confused when I saw an HTML response when fetching '/contacts.json'.
After I changed 'repond_to :html' to 'respond_to :html, :json' -- I was confused when I saw an HTML response when fetching '/contacts.json'.
Renaming 'app/views/contacts/index.haml' to index.html.haml' solved the problem, Rails no longer used index.haml to render the JSON response.