Search code examples
ruby-on-railsjbuilder

How to check or setup view template extension


I have jbuilder file:

app/views/api/items/show.json.jbuilder

code

render :show
#or
render :show, template: "api/items/show"

does not worked - template is missing, but code

render :show, template: "api/items/show.json"

worked fine.

What is wrong? What need to check? Which file to see or what to dump?


Solution

  • You will have to use the respond_to method to tell Rails you're responding to a json request.

    def show
      respond_to do |format|
        format.json
      end
    end