Unknown format in rails 4

2020-02-10 17:39发布

I'm using rails 4. But I am getting unknown format error. Do you guys have any help for me. Here is my controller:

class EntriesController < ApplicationController
  respond_to :json

  def index
    respond_with Entry.all
  end
end

enter image description here

3条回答
一纸荒年 Trace。
2楼-- · 2020-02-10 18:10

Add :html to respond_to (respond_to :html, :json) or remove the respond_to call altogether.

查看更多
倾城 Initia
3楼-- · 2020-02-10 18:16

Add this to your routes config

resources :entries, defaults: { format: 'json' }

查看更多
Explosion°爆炸
4楼-- · 2020-02-10 18:19
def index
  respond_to do |format|

    @entry = Entry.all

    format.html 
    format.json { render json: @entry }

  end
end

hope it will help you

查看更多
登录 后发表回答