Devise中的ArgumentError :: Registrations#new

时间:2016-11-30 11:55:02

标签: ruby-on-rails ruby devise

  

注意: ruby​​ 2.3.0,Rails 5.0.0.1,设计(4.2.0)

视图/设计/注册/ new.html.erb

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-horizontal' }) do |f| %>

应用程序跟踪

app/views/devise/registrations/new.html.erb:6:in `_app_views_devise_registrations_new_html_erb__2494954624473792684_38973380'

完整跟踪

breach-mitigation-rails (0.2.2) lib/breach_mitigation/railtie.rb:30:in `form_authenticity_token'
actionpack (5.0.0.1) lib/abstract_controller/helpers.rb:68:in `form_authenticity_token'
actionview (5.0.0.1) lib/action_view/helpers/url_helper.rb:589:in `token_tag'
actionview (5.0.0.1) lib/action_view/helpers/form_tag_helper.rb:866:in `extra_tags_for_form'
actionview (5.0.0.1) lib/action_view/helpers/form_tag_helper.rb:886:in `form_tag_html'
actionview (5.0.0.1) lib/action_view/helpers/form_tag_helper.rb:891:in `form_tag_with_body'
actionview (5.0.0.1) lib/action_view/helpers/form_helper.rb:454:in `form_for'
/home/vagrant/.rvm/gems/ruby-2.3.0/bundler/gems/simple_form-5fcefffdadd6/lib/simple_form/action_view_extensions/form_helper.rb:26:in `block in simple_form_for'
/home/vagrant/.rvm/gems/ruby-2.3.0/bundler/gems/simple_form-5fcefffdadd6/lib/simple_form/action_view_extensions/form_helper.rb:45:in `with_simple_form_field_error_proc'
/home/vagrant/.rvm/gems/ruby-2.3.0/bundler/gems/simple_form-5fcefffdadd6/lib/simple_form/action_view_extensions/form_helper.rb:25:in `simple_form_for'
app/views/devise/registrations/new.html.erb:6:in `_app_views_devise_registrations_new_html_erb__2494954624473792684_38973380'
actionview (5.0.0.1) lib/action_view/template.rb:158:in `block in render'
activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `instrument' 

Rake路线输出

        new_user_session GET      /users/sign_in(.:format)                                                                 devise/sessions#new
              user_session POST     /users/sign_in(.:format)                                                                 devise/sessions#create
      destroy_user_session DELETE   /users/sign_out(.:format)                                                                devise/sessions#destroy
             user_password POST     /users/password(.:format)                                                                devise/passwords#create
         new_user_password GET      /users/password/new(.:format)                                                            devise/passwords#new
        edit_user_password GET      /users/password/edit(.:format)                                                           devise/passwords#edit
                           PATCH    /users/password(.:format)                                                                devise/passwords#update
                           PUT      /users/password(.:format)                                                                devise/passwords#update
  cancel_user_registration GET      /users/cancel(.:format)                                                                  devise/registrations#cancel
         user_registration POST     /users(.:format)                                                                         devise/registrations#create
     new_user_registration GET      /users/sign_up(.:format)                                                                 devise/registrations#new
    edit_user_registration GET      /users/edit(.:format)                                                                    devise/registrations#edit
                           PATCH    /users(.:format)                                                                         devise/registrations#update
                           PUT      /users(.:format)                                                                         devise/registrations#update
                           DELETE   /users(.:format)                                                                         devise/registrations#destroy
         user_confirmation POST     /users/confirmation(.:format)                                                            devise/confirmations#create
     new_user_confirmation GET      /users/confirmation/new(.:format)                                                        devise/confirmations#new
                           GET      /users/confirmation(.:format)                                                            devise/confirmations#show
                   sign_in GET      /sign_in(.:format)                                                                       devise/sessions#new
                           GET      /sign-in(.:format)                                                                       devise/sessions#new
                   sign_up GET      /sign_up(.:format)                                                                       devise/registrations#new
                           GET      /sign-up(.:format)                                                                       devise/registrations#new

完整错误

ArgumentError in Devise::Registrations#new wrong number of arguments (given 1, expected 0)

我将rails升级到5,这似乎请帮我解决Thanx:)

更新了视图/设计/注册/ new.html.erb

<%= form_for(resource, :as => resource_name, :url => user_registration_path, :html => {:class => 'form-horizontal' }) do |f| %>
  <%= devise_error_messages! %>

  <div class="inputs">
    <%= f.text_field :email, :autofocus => true, :input_html => { :autocomplete => "off" } %>
</div>

  <div class="actions">
    <%= f.submit "Sign up" %>
  </div>

2 个答案:

答案 0 :(得分:2)

更新

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-horizontal' }) do |f| %>

<%= simple_form_for(resource, :as => resource_name, :url => user_registration_path, :html => {:class => 'form-horizontal' }) do |f| %>

答案 1 :(得分:2)

根据您的路线,您有

<强> user_registration POST /users(.:format)

这将 post 改为 /users ,这是 create 的行动> registration 即可。

所以表格应该是。

<%= form_for(resource, :as => resource_name, :url => user_registration_path) do |f| %>
        <%= devise_error_messages! %>

        <%= f.text_field :email %>
<%end %>