gpt4 book ai didi

ruby-on-rails - Rails:ActionDispatch::Request 的未定义方法 `flash'

转载 作者:行者123 更新时间:2023-12-03 11:30:20 30 4
gpt4 key购买 nike

我正在尝试在 Rails 4 中编写 Ember 应用程序,并决定使用 rails-api对于 api Controller ,同时为不属于单页应用程序的几个页面保持应用程序 Controller 完整。更具体地说,这是我的 Controller :
app/controllers/application_controller.rb :

class ApplicationController < ActionController::Base
protect_from_forgery
end
app/controllers/sample_controller.rb :
class SampleController < ApplicationController
# my methods
end
app/controllers/api/v1/api_controller.rb :
class Api::V1::ApiController < ActionController::Api
include ActionController::MimeResponds
end
app/controllers/api/v1/sample_controller.rb :
module Api::V1
class SampleController < ApiController
respond_to :json

# my methods

end
end

我的 application.html.slim包含以下行:
== render partial: "flash_msgs" unless flash.blank?

包含其中会导致以下错误:

undefined method 'flash' for #< ActionDispatch::Request:0x007f99f41d8720 >



每次讨论 on this thread ,看来罪魁祸首可能是 rails-api ,但考虑到我建立的继承,我并不完全相信。有什么建议?

最佳答案

不确定,但也许您需要包含 ActionDispatch::Flash中间件支持flash。使用:

config.middleware.use ActionDispatch::Flash

docs说:

ActionDispatch::Flash: Supports the flash mechanism in ActionController.



我希望它有帮助

关于ruby-on-rails - Rails:ActionDispatch::Request 的未定义方法 `flash',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19600905/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com