I'm using the Rails API (doesn't use Flash Middleware). I'm finding that when I try CURL'ing to the reset password the response appears to be in HTML format which is an error that says.
<h2>undefined local variable or method `flash' for #<PasswordsController:0x007fbb11fcf598></h2>
HTML format has been disabled too which is why its a little strange that its trying to respond this way.
curl -X POST 'http://localhost:3001/users/password.json' -d 'user[email][email protected]'
class PasswordsController < Devise::PasswordsController
respond_to :json
respond_to :html, only: []
respond_to :xml, only: []
end
Any thoughts as to why this might be happening?
Pry is showing the following:
pry(#<PasswordsController>)> successfully_sent?(resource)
NameError: undefined local variable or method `flash' for #<PasswordsController:0x007fbb0cdaaa10>
Which is from this line
https://github.com/plataformatec/devise/blob/f5f7e97d8bc368b87bdbcc0e4c4ecea3b7378684/app/controllers/devise_controller.rb#L126
Which is finally ending up here
https://github.com/plataformatec/devise/blob/c67de7e91cc3ea201c7cedc0ed71e1f6c76b2d36/lib/devise/controllers/helpers.rb#L186
When I look into that, the request is showing:
pry(#<PasswordsController>)> @request_format ||= request.format.try(:ref)
=> "*/*"
Which is set from the devise.rb initalizer. The advice here is that this is required for IE.
https://github.com/plataformatec/devise/blob/v3.1/lib/generators/templates/devise.rb#L225-L226
# The "*/*" below is required to match Internet Explorer requests.
# config.navigational_formats = ['*/*', :html]
I've actually got this set to json and the wildcard. I want to accept json only, but also need to factor in users with IE?
config.navigational_formats = ['*/*', :json]
If I remove the '_/_' and restart the server, I then get the following error with the same CURL
Redirected to
Completed 500 Internal Server Error in 602ms
ArgumentError (Nil location provided. Can't build URI.):
If disabled all together then it seems to work from an AJAX call from the front end, however a CURL command still fails with
NameError (undefined local variable or method `flash' for #<PasswordsController:0x007f8f150ff040>):
@rsiddle you don't need to add :json to navigational_formats actually since it's not navigational format. So config.navigational_formats = ['*/*', :html] doesn't work for you, right?
I'm looking to remove HTML all together. At the moment its quite painful because I'm trying to remove it all manually
Yeah, if you send an explicit format (like json or js), it should work as it stop being considered navigational.
Defining the format as json in routes.rb worked well for me:
devise_for :users, defaults: { format: :json }
Most helpful comment
Defining the format as json in
routes.rbworked well for me: