Rails 4 - 设计 3 不工作(Users::RegistrationController#create 中的 NoMethodError)

Rails 4 - Devise 3 not working (NoMethodError in Users::RegistrationController#create )

Devise 无法像以前那样工作 Rails 4. 我没有更改我的用户模型中的任何内容。看起来像这样 -

create_table(:users) do |t|
  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  t.integer  :sign_in_count, :default => 0
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.string   :current_sign_in_ip
  t.string   :last_sign_in_ip

  t.timestamps
end

add_index :users, :email,                :unique => true
add_index :users, :reset_password_token, :unique => true

我的设计路线看起来像这样 -

devise_for :users, path: "", controllers: {
                   sessions: "users/session",
                   registrations: "users/registration",
                   passwords: "users/password"
               }, path_names: {
                   sign_in: 'login',
                   password: 'forgot',
                   confirmation: 'confirm',
                   unlock: 'unblock',
                   sign_up: 'register',
                   sign_out: 'logout'
               }

当我尝试从默认注册页面注册时,即 registrations/new.html.erb,我收到以下错误 -

NoMethodError in Users::RegistrationController#create

undefined method `deep_symbolize_keys' for #Array:0x007f8b33bcd750

我的注册表如下所示(非常基本)-

<%= form_for(resource, :as => resource_name, :url => user_registration_path(resource_name)) do |f| %>
  <fieldset>
    <legend><h5 class="color1">Sign up</h5></legend>

    <%= devise_error_messages! %>

    <%= f.text_field :first_name, :placeholder => "Your first name", :autofocus => true %>

    <%= f.text_field :last_name, :placeholder => "Your last name" %>

    <%= f.text_field :email, :placeholder => "Your email address" %>

    <%= f.phone_field :phone_number, :placeholder => "Your phone number (Optional)" %>

    <%= f.password_field :password, :placeholder => "Your password" %>

    <%= f.password_field :password_confirmation, :placeholder => "Please confirm your password" %>

    <%= content_tag :button, :type => :submit, :class => "button small success" do %>
       Sign up
      <% end %>

 </fieldset>
<% end %>

我尝试过的解决方案:

  1. 我尝试更新所有的 gems(包括 Devise,目前是 3.4,以前是 3.0),仍然没有成功
  2. 删除数据库,重新创建并运行所有迁移,运气不好
  3. 试图创建一个新的控制器并继承自 Devise::RegistrationsController,失败了

编辑: 我的控制器代码如下所示 -

class Users::RegistrationController < Devise::RegistrationsController
end

application.rb 看起来像这样 -

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module AppName
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
  end
end

我错过了什么?任何帮助将不胜感激!

抱歉这个问题太长了!

好的,我找到了。

正如 Alex 所建议的,我注意到错误发生在 i18n store_translations 方法中。

我在谷歌上搜索了一下,发现了这个 - https://github.com/plataformatec/devise/issues/337

正如 Steven 在那个 github 线程中指出的那样,报告该问题的人在 config/locales 下有一些奇怪的 yml,我也是。

我删除了 yml,它似乎工作得很好!