'Use ActionDispatch::Flash on middleware rails
I'm a newbie in Ruby and I'm trying to integrate google re-captcha gem on my Rails application https://github.com/ambethia/recaptcha/.
It works well on localhost, but in production throws this error:
ActionView::Template::Error (undefined method `flash' for Node ID: franchises_form Parent: root Children: 0 Total Nodes: 1:FranchisesFormWidget):
119: </input>
120: </div>
121:
122: <%= recaptcha_tags %>
123:
124: </br><small>bla bla bla</small>
I've been searching on the web, and all the solutions suggest using
config.middleware.use ActionDispacth::Flash
The problem is that I don't really know where to introduce it. I tried at application.rb, at the recaptcha config file, and at FranchisesFormWidget, which calls the gem's methods for displaying the recaptcha form.
In application.rb I've got references to middleware management:
class Refinery::Resources::Engine
initializer 'delete rack cache' do |app|
app.config.middleware.delete Rack::Cache
end
end
class Refinery::Images::Engine
initializer 'delete rack cache' do |app|
app.config.middleware.delete Rack::Cache
end
end
So, for example, I added this:
class FranchisesFormWidget
initializer 'use action dispatch flash' do |app|
app.config.middleware.use ActionDispatch::Flash
end
end
But gives me another error (which I don't remember). What I am doing wrong? What must I do?
Solution 1:[1]
Their documentation (found here: https://www.rubydoc.info/github/ambethia/recaptcha/master/file/README.md#rails-installation) show no configuration for a rails project beyond adding the gem to your gem file and using your api key. It should work out of the box.
If you are using Rails as an API it does not configure the ActionDispatch::Flash and you will have to configure that in your application.rb. You can follow some suggestions on this thread Rails: Undefined method `flash' for ActionDispatch::Request
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
