Rails 4 Devise 3.1.1 ActionController::UnknownFormat in Devise::RegistrationsController#new

前端 未结 4 704
傲寒
傲寒 2021-01-05 08:02

I am working on a Rails 4 app using Devise 3.1.1 for user authentication. When I click on /users/sign_up.user link Rails throws following exception:

ActionCo         


        
相关标签:
4条回答
  • 2021-01-05 08:30

    I did not want to change default links produced by Devise which appended ".user" at the end of each link. Devise produced following links:

    new_user_registration_path(resource_name) new_user_session_path(resource_name) new_user_password_path(resource_name)

    resource_name, which is user, as parameter to the path in link_to method which tells it to use ".user" as format. So I just removed resource_name from each path. I wonder why Devise does this though!

    0 讨论(0)
  • 2021-01-05 08:31

    When you say you click on the /users/sign_up.user link, do you literally mean that exact path? Because the .user on the end is telling it to try and respond with a user format, akin to pdf, xml, or json. Remove that and see what happens.

    0 讨论(0)
  • 2021-01-05 08:32

    I've just resolved this problem also.

    The solution is to revert all paths to Devise default ones, meaning to say no _user infix.

    Note that we are not able to test in console these code:

    user = User.all.sample
    app.new_registration_path(user)
    

    because Devise use its helper to transform the url automatically internally so we cannot test from outside.

    0 讨论(0)
  • 2021-01-05 08:37

    @zeeshan's answer works, you can also the functions without the _user infix:

    new_registration_path(resource_name)
    
    new_session_path(resource_name)
    
    new_password_path(resource_name)
    
    0 讨论(0)
提交回复
热议问题