niftygrifty
niftygrifty

Reputation: 3652

UnknownFormat in Devise::SessionsController#new

I have a Rails 4 app (that was upgraded from Rails 3) in which I decided to delete one of the controllers. I then moved the methods from that deleted controller to the ApplicationController, which included before_filter :authenticate_user!

Here's what my ApplicationController looks like now:

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :authenticate_user!
  respond_to :json

  def index
    gon.rabl

    @user = current_user
    gon.rabl "app/views/users/show.json.rabl", as: "current_user"
  end

  def markdown
    require 'redcarpet'
    renderer = Redcarpet::Render::HTML.new
    extensions = {}
    Redcarpet::Markdown.new(renderer, extensions)
  end

  helper_method :markdown

end

Now, I'm getting this error:

ActionController::UnknownFormat in Devise::SessionsController#new

Upvotes: 0

Views: 2466

Answers (3)

Michael
Michael

Reputation: 621

Thanks Slicedpan. Got me thinking about a

respond_to :json

Used in my Rails Application as an API with Angular. As in my Rails controllers I use for requests from my Angular Services.

respond_with

In my case I ended up adding html to the respond_to:

respond_to :json, :html

The Default Mime Types can be seen here: http://apidock.com/rails/Mime

Upvotes: 0

universa1
universa1

Reputation: 172

You shouldn't have the index method defined in application_controller. You should move it to the appropriate controller. If this is something you want to do before every action you might want to try something like this:

before_action :gon_user, only: :index
private
def gon_user
  gon.rabl

  @user = current_user
  gon.rabl "app/views/users/show.json.rabl", as: "current_user"
end

Though i've to be honest that i'm not sure about the gon stuff, can't remember if it was for moving data from ruby to javascript or for responding to ajax/json request.

Upvotes: 1

Slicedpan
Slicedpan

Reputation: 5015

I think this might be due to the fact that you have set your application controller to respond only to json. If your Devise Controller inherits from ApplicationController (I think this is the default), then it will expect to see a content-type: json header, or your urls must all end in .json

Upvotes: 5

Related Questions