Rails:ActionDispatch::Request 的未定义方法`flash' [英] Rails: Undefined method `flash' for ActionDispatch::Request

查看:43
本文介绍了Rails:ActionDispatch::Request 的未定义方法`flash'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Rails 4 中编写 Ember 应用程序,并决定为 api 控制器使用 rails-api,同时保持应用程序控制器完整地用于一些页面t 单页应用程序的一部分.更具体地说,这是我的控制器:

I'm trying to write an Ember application in Rails 4, and have decided to go with rails-api for the api controllers, while keeping the application controller intact for a few pages that aren't part of the single-page app. To put it in more concrete terms, here are my controllers:

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?

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

The inclusion of which results in the following error:

未定义的方法 'flash' for #<ActionDispatch::Request:0x007f99f41d8720 >

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

根据讨论 在此线程上,似乎罪魁祸首可能是 rails-api,但鉴于我设置的继承,我并不完全相信.有什么建议吗?

Per discussion on this thread, it seems that the culprit could be rails-api, but I'm not entirely convinced given the inheritance I've set up. Any suggestions?

推荐答案

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

Not sure but maybe you need to include the ActionDispatch::Flash middleware to support the flash. Using:

config.middleware.use ActionDispatch::Flash

文档 说:

ActionDispatch::Flash:支持 Flash 机制动作控制器.

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

希望能帮到你

这篇关于Rails:ActionDispatch::Request 的未定义方法`flash'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆