我有一个Rails 4.2.3应用程序,我在其中使用Devise进行用户身份验证。我在Bootstrap模态框中呈现我的注册表单。我已经按照以下方式实现它:https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app。在注册时,我一直收到以下错误:
我的应用程序在
在我的
注意:运行宝石
Completed 406 Not Acceptable in 512033ms (ActiveRecord: 5.8ms)
ActionController::UnknownFormat (ActionController::UnknownFormat)
我不确定如何修复它。
我针对会话和注册使用自定义控制器。我的路由目前看起来是这样的:
devise_for :users, :controllers => {sessions: "users/sessions", registrations: "users/registrations"}
get 'users/show', to: "users#show"
get 'users', to: "users#index"
我的新用户表单长这样——它被渲染在一个Bootstrap模态框中的部分中:
= 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"
我的应用程序在
Users::RegistrationsController < Devise::RegistrationsController
的create
方法中崩溃:# POST /resource
def create
# byebug
super
end
浏览器中的URL如下(看起来可疑!):
http://localhost:3000/users.user
我尝试添加:
respond_to :json, :html
在我的
Users::RegistrationsController < Devise::RegistrationsController
的顶部加入了一些内容,但是没有帮助到我。注意:运行宝石
bye bug
后,应用程序似乎在此方法中崩溃:# 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]
返回 "/apps/1/edit"
你有什么想法,我在这里或其他地方做错了吗?
附注 我同时遇到了另一个Devise问题(它们可能相关)。我在这里有另一个问题:Rails 4 - Devise, guest users causes filter chain halted
Users::RegistrationsController < Devise::RegistrationsController
中的create
操作就永远不会被调用了,似乎用户也没有被创建。相反,在我的 ApplicationController 中调用了另一个操作:def after_sign_in_path_for(resource)
。这可能与我尝试使用的客人用户有关( https://dev59.com/opHea4cB1Zd3GeqPlSVO)。但是,改变参数会以某种方式防止调用create
操作。 - Anders