Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 - Devise: getting ActionController::UnknownFormat on signup

I have a Rails 4.2.3 app where I use Devise for user authentication. I present my signup form in a Bootstrap modal. I have implemented it similar to: https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app. On signup I keep getting this error:

Completed 406 Not Acceptable in 512033ms (ActiveRecord: 5.8ms)
ActionController::UnknownFormat (ActionController::UnknownFormat)

And I'm not sur how to fix it.

I use custom controllers for sessions and registrations. My routes currently looks like this:

devise_for :users, :controllers => {sessions: "users/sessions", registrations: "users/registrations"}

get 'users/show', to: "users#show"
get 'users', to: "users#index"

My new user form looks like this - this gets rendered in a partial that is presented in a Bootstrap modal:

= form_for(resource, as: resource_name, url:  user_registration_path(resource_name)) do |f|
  = devise_error_messages!
  .form-group
    = f.label :name
    = f.text_field :name, autofocus: true, class: "form-control"
  .form-group
    = f.label :email
    = f.email_field :email, class: "form-control"

  .form-group
    = f.label :password
    - if @minimum_password_length
      %em
        (#{@minimum_password_length} characters minimum)
    = f.password_field :password, autocomplete: "off", class: "form-control"

  .form-group
    = f.submit "Sign up", class: "btn btn-default"

- if current_page?(new_user_registration_path)
  = render "devise/shared/links" 

The app crashes in my Users::RegistrationsController < Devise::RegistrationsController create method:

# POST /resource
def create
  # byebug
  super
end

And the url in the browser is the following (looks suspicious!):

http://localhost:3000/users.user

I have tried adding:

respond_to :json, :html

At the top of my Users::RegistrationsController < Devise::RegistrationsController, but that didn't help.

Note

After running the gem bye bugthe app seems to crash in this method:

# The path used after sign up.
def after_sign_up_path_for(resource)
  byebug
  session[:previous_url] || root_path # crashes here
end

session[:previous_url] returns "/apps/1/edit"

Any ideas on what I'm doing wrong here, or anywhere else?

Sidenote I'm simultaneously struggling with another devise issue (they may be related). I have another question for that here: Rails 4 - Devise, guest users causes filter chain halted

like image 527
Anders Avatar asked Nov 22 '15 20:11

Anders


Video Answer


1 Answers

Just change this in your form:

= form_for(resource, as: resource_name, url: user_registration_path) do |f|

user_registration_path does not requires an additional parameter, and you pass the resource_name to it, which is equal to user in your case. It gets interpreted as the format, and therefore you get url like http://localhost:3000/users.user (user is set as a format in this case).

like image 131
Yury Lebedev Avatar answered Sep 28 '22 16:09

Yury Lebedev