2015-04-22 59 views
0

我正在使用简单令牌认证的设计用于用户在restfull webService中进行身份验证。但是,当我使用无效令牌发出申请时,我会收到下面的错误消息。它可以做什么?json自定义设计会话控制器错误

Started GET "https://stackoverflow.com/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' 
+1

使用有效的标记问题...你可以稍微对你是什么错误更具体,你找什么做的? –

+0

我使用无效令牌时出现此错误。但是我期待在{“status”:401,“message”:“无效凭证”}这样的json中出现错误消息。这种错误发生在新方法中,我无法找到原因。 –

回答

0

我解决我的

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