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

时间:2015-01-26 03:02:51

标签: ruby-on-rails ruby-on-rails-4 devise

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,我收到以下错误 -

  

用户:: RegistrationController #create

中的NoMethodError      

#Array的未定义方法`deep_symbolize_keys':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. 我试图更新所有的宝石(包括目前在3.4的Devise,使用的是3.0),仍然没有运气
  2. 删除数据库,再次重新创建并运行所有迁移,没有运气
  3. 试图创建一个新的控制器并继承自Devise :: RegistrationsController,没有运气
  4. 编辑:我的控制器代码如下所示 -

    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
    

    我错过了什么?任何帮助将非常感谢!

    很抱歉这个很长的问题!

1 个答案:

答案 0 :(得分:1)

好的,我发现了发生了什么。

正如Alex建议的那样,我注意到i18n store_translations方法中出现了错误。

我做了一些谷歌搜索,我遇到了这个 - https://github.com/plataformatec/devise/issues/337

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

我删除了yml,它似乎工作正常!