Ruby on rails 使用json的自定义设计会话控制器错误

Ruby on rails 使用json的自定义设计会话控制器错误,ruby-on-rails,json,devise,Ruby On Rails,Json,Devise,我在restfull Web服务中使用Desive和简单令牌身份验证进行用户身份验证。但是,当我使用无效令牌发出请求时,会出现以下错误。它能做什么 Started GET "/users/sign_in.json" for ::1 at 2015-04-22 16:09:27 -0300 Processing by SessionsController#new as JSON Completed 406 Not Acceptable in 4ms ActionController::Unkno

我在restfull Web服务中使用Desive和简单令牌身份验证进行用户身份验证。但是,当我使用无效令牌发出请求时,会出现以下错误。它能做什么

Started GET "/users/sign_in.json" for ::1 at 2015-04-22 16:09:27 -0300
Processing by SessionsController#new as JSON
Completed 406 Not Acceptable in 4ms

ActionController::UnknownFormat (ActionController::UnknownFormat):
  responders (2.1.0) lib/action_controller/respond_with.rb:205:in `respond_with'
  devise (3.4.1) app/controllers/devise/sessions_controller.rb:11:in `new'
  actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
  actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'

我用电脑解决了我的问题

class SessionsController < Devise::SessionsController
  respond_to :html, :json

  def new
    self.resource = resource_class.new(sign_in_params)
    clean_up_passwords(resource)
    yield resource if block_given?
    respond_with(resource, serialize_options(resource)) do |format|
      format.json { render :json => { :message => "Forbidden"},:status => :unauthorized }
    end
  end
  ...
end
class sessioncontroller{:message=>“禁止”},:status=>:unauthorized}
结束
结束
...
结束

使用有效的令牌…您能否更具体地说明您的错误是什么以及您希望做什么?当我使用无效令牌时,会出现此错误。但我希望json中会出现类似{“status”:401,“message”:“Invalid credentials”}的错误消息。这个错误发生在新方法中,我无法发现原因。