Ruby on rails designe:Sesson上的JSON消息#Destroy
我正在尝试在Rails 5应用程序中为Desive注销时获取JSON响应消息Ruby on rails designe:Sesson上的JSON消息#Destroy,ruby-on-rails,json,devise,Ruby On Rails,Json,Devise,我正在尝试在Rails 5应用程序中为Desive注销时获取JSON响应消息 class SessionsController < Devise::SessionsController around_action :after_logout_message protected def after_logout_message set_flash_message! :notice, :signed_out yield en
class SessionsController < Devise::SessionsController
around_action :after_logout_message
protected
def after_logout_message
set_flash_message! :notice, :signed_out
yield
end
private
def respond_to_on_destroy
# We actually need to hardcode this as Rails default responder doesn't
# support returning empty response on GET request
respond_to do |format|
format.json { render json: flash }
format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
end
end
end
为什么这样不行?其他每一个动作似乎都能很好地处理这个问题。如果你把
flash[:notice]
行放在收益率之后,会有什么变化吗?是的,当我手动设置一个flash,比如flash[:notice]=something
。但当我将其更改为设置\u flash\u message!:注意:已注销它不起作用。知道我为什么或者应该发布另一个问题吗?更新:它使用app.flash
从rails控制台显示,但是尝试卷曲仍然不会返回任何结果(当执行flash[:notice]=“test”
)。听起来它值得一个新问题。我在谷歌上搜索了文档(),很可能这只是一个“setflash.now
”问题,但看起来你是故意这么做的,所以可能不是那样……是的,我不知道json版本实际上会返回flash…:/但我从未尝试过。。。
get 'login', to: 'sessions#new', as: :new_user_session
post 'login', to: 'sessions#create', as: :user_session
match 'logout', to: 'sessions#destroy', as: :destroy_user_session, via: Devise.mappings[:user].sign_out_via