I am using Devise with Ruby on Rails. I have a few pages that I am using with a different mime-type – say /myapp/products.test … so I have registered a mime-type called ‘test’ and it resembles text/html … and I have content negotiation to either display the html.erb template or the test.erb template …
Now – when I have an authenticate_user! method in my controller – and I am using the ‘test’ mime-type – I don’t properly get redirected – I don’t get redirected at all – I just get a “You need to log in or sign up before continuing.” message.
What in Devise needs to overridden, so that it redirects when I use a mime-type other than html?
I found part of the answer on the following wiki page: https://github.com/plataformatec/devise/wiki/How-To:-Make-Devise-work-with-other-formats-like-mobile,-iphone-and-ipad-(Rails-specific)
So – in summary (besides registering the mime type etc as explained in the question):
In the config/initializers/devise.rb file, uncomment the config.navigational_formats line and replace with:
Add a file to the initializers, and add the following to it:
I also needed to override a devise method because my mime type actually responds to html too – but I do want to see whether it also responds to :test. So again in the initializers folder, add a file that contains the following:
It may be that it would have been cleaner – instead of overriding the above method – to override a method in Warden that does the redirect to the unauthorized url – but I couldn’t quite figure it out, and also uncertain whether Devise (upstream) isn’t the better place to override methods.