Rails 4-设计:在注册时获取ActionController :: UnknownFormat [英] Rails 4 - Devise: getting ActionController::UnknownFormat on signup
问题描述
我有一个Rails 4.2.3应用程序,其中使用Devise进行用户身份验证。我以Bootstrap模式显示我的注册表单。我已经实现了类似于: https://github.com/plataformatec/devise/wiki/操作方法:-Display-a-custom-sign_in-form-anywhere-in-your-app 。在注册时,我不断收到此错误:
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"
我的新用户表单如下所示-这部分呈现为以Bootstrap模式显示:
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"
应用在我的中崩溃用户:: RegistrationController< Devise :: RegistrationsController
create
方法:
# POST /resource
def create
# byebug
super
end
浏览器中的网址如下(看起来可疑!):
And the url in the browser is the following (looks suspicious!):
http://localhost:3000/users.user
我尝试添加:
respond_to :json, :html
在我的 Users :: RegistrationsController的顶部< Devise :: RegistrationsController
,但这没有帮助。
At the top of my Users::RegistrationsController < Devise::RegistrationsController
, but that didn't help.
注意
运行gem 再见错误后
该应用似乎以这种方式崩溃:
After running the gem bye bug
the 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]
返回 / apps / 1 / edit
关于我的想法在这里还是其他地方做错了?
Any ideas on what I'm doing wrong here, or anywhere else?
边注
我同时还在努力解决另一个设计问题(它们可能是相关的)。我在这里还有另一个问题:第4条-设计,访客用户导致过滤器链停止
推荐答案
只需更改以下形式:
= form_for(resource, as: resource_name, url: user_registration_path) do |f|
user_registration_path
不需要其他参数,然后将 resource_name
传递给它,在您的情况下,它等于 user
。它被解释为格式,因此您将获得 http:// localhost:3000 / users.user
( user
在这种情况下被设置为格式。)
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).
这篇关于Rails 4-设计:在注册时获取ActionController :: UnknownFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!