ruby-on-rails – Rails 4 – 设计:在注册时获取ActionControll
我有一个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” 关于我在这里或其他地方做错的任何想法? 边注 解决方法
只需在表单中更改:
= form_for(resource,url: user_registration_path) do |f| user_registration_path不需要额外的参数,您将resource_name传递给它,在您的情况下等于user.它被解释为格式,因此您可以获得类似http:// localhost:3000 / users.user的URL(在这种情况下,用户被设置为格式). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |