加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails 4 – 设计:在注册时获取ActionControll

发布时间:2020-12-17 03:56:47 所属栏目:百科 来源:网络整理
导读:我有一个Rails 4.2.3应用程序,我使用Devise进行用户身份验证.我在Bootstrap模式中呈现我的注册表单.我已经实现了类似于: https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app.在注册时我不断收到此
我有一个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创建方法:

# POST /resource
def create
  # byebug
  super
end

浏览器中的URL如下(看起来很可疑!):

http://localhost:3000/users.user

我试过添加:

respond_to :json,:html

在我的Users :: RegistrationsController顶部< Devise :: RegistrationsController,但没有帮助. 注意 在运行gem 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”

关于我在这里或其他地方做错的任何想法?

边注
我同时正在努力解决另一个设计问题(它们可能是相关的).我在这里有另一个问题:Rails 4 – Devise,guest users causes filter chain halted

解决方法

只需在表单中更改:

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

user_registration_path不需要额外的参数,您将resource_name传递给它,在您的情况下等于user.它被解释为格式,因此您可以获得类似http:// localhost:3000 / users.user的URL(在这种情况下,用户被设置为格式).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读