Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `flash' for #<ActionDispatch::Request

I have stuff with Ruby on Rails 3

I try this simple code

  def index
    flash[:notice] = "ok"
    respond_to do |format|
      format.html # index.html.erb
    end
  end

it does not work

NoMethodError in DashboardsController#index
undefined method `flash' for #<ActionDispatch::Request:0x7fee9329a9d0>

When I try

redirect_to :some_in, :notice => "ok"

in other place (in some_controller.rb) and then print this :notice in .erb I have same error, undefined method `flash'

I'm stuck on this. I used google to search for it but it does not help.

like image 748
user1148210 Avatar asked May 13 '26 01:05

user1148210


2 Answers

In config/applications.rb of your app add this

config.api_only = false
like image 53
Sharvil Avatar answered May 14 '26 14:05

Sharvil


Please include ActionDispatch::Flash middleware into your config/application.rb file.

config.middleware.use ActionDispatch::Flash

This may help you.

like image 30
Amol Udage Avatar answered May 14 '26 14:05

Amol Udage