仅限生产中的ActionController :: RoutingError(未初始化的常量成员)

时间:2018-02-12 18:18:06

标签: ruby-on-rails heroku devise

我已经阅读了很多不同的问题,但找不到我的答案。似乎所有其他人都在开发中遇到这个问题,这是由于命名问题。在开发过程中,一切都适合我,但生产中的错误。

WebApp信息:

Rails: 5.1.4

Ruby: 2.5.0p0(2017-12-25修订版61468)[x86_64-darwin17]

已部署至: Heroku

收到错误:

2018-02-12T17:59:43.693569+00:00 heroku[router]: at=info method=GET path="/login" host=the-christian-chain.herokuapp.com request_id=9933c1eb-5023-4814-976d-a656053794d3 fwd="137.152.185.249" dyno=web.1 connect=1ms service=5ms status=404 bytes=1902 protocol=https
2018-02-12T17:59:43.690742+00:00 app[web.1]: I, [2018-02-12T17:59:43.690635 #4] INFO  -- : [9933c1eb-5023-4814-976d-a656053794d3] Started GET "/login" for 137.152.185.249 at 2018-02-12 17:59:43 +0000
2018-02-12T17:59:43.692591+00:00 app[web.1]: F, [2018-02-12T17:59:43.692522 #4] FATAL -- : [9933c1eb-5023-4814-976d-a656053794d3]   
2018-02-12T17:59:43.692655+00:00 app[web.1]: F, [2018-02-12T17:59:43.692591 #4] FATAL -- : [9933c1eb-5023-4814-976d-a656053794d3] ActionController::RoutingError (uninitialized constant Members):
2018-02-12T17:59:43.692715+00:00 app[web.1]: F, [2018-02-12T17:59:43.692656 #4] FATAL -- : [9933c1eb-5023-4814-976d-a656053794d3]   
2018-02-12T17:59:43.692815+00:00 app[web.1]: F, [2018-02-12T17:59:43.692738 #4] FATAL -- : [9933c1eb-5023-4814-976d-a656053794d3] vendor/bundle/ruby/2.5.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:in `const_get'
....

然后它列出了一堆其他请求,直到主页的最后GET

我遇到了一个问题,即应用程序在将其部署到具有相同uninitialized constant Members类型问题的Heroku后会崩溃。所以,我把eager_load改为false,这似乎解决了这个问题。但是,现在看到这个,我想知道我的代码中是否存在更大的问题。

此处将其更改为false: 配置/环境/ production.rb

....
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = false
....

我的路线文件部分带有设计路线:

配置/ routes.rb中

######################
###    Members     ###
######################

  devise_for :members, 
              controllers: {
                sessions: 'members/sessions',
                registrations: 'members/registrations'
              },
              path: '', path_names: { 
                  sign_in:    'login', 
                  sign_out:   'logout', 
                  sign_up:    'register',
                  edit:       ':username/account/edit'
              }

我可以确认定制的Devise控制器是否正确嵌套,拼写是正确的,因为登录和注册都在开发中本地工作。

这是我运行heroku rake routes

时MembersController的结果
        new_member_session GET    /login(.:format)                       members/sessions#new
            member_session POST   /login(.:format)                       members/sessions#create
    destroy_member_session DELETE /logout(.:format)                      members/sessions#destroy
       new_member_password GET    /password/new(.:format)                devise/passwords#new
      edit_member_password GET    /password/edit(.:format)               devise/passwords#edit
           member_password PATCH  /password(.:format)                    devise/passwords#update
                           PUT    /password(.:format)                    devise/passwords#update
                           POST   /password(.:format)                    devise/passwords#create
cancel_member_registration GET    /cancel(.:format)                      members/registrations#cancel
   new_member_registration GET    /register(.:format)                    members/registrations#new
  edit_member_registration GET    /:username/account/edit(.:format)      members/registrations#edit
       member_registration PATCH  /                                      members/registrations#update
                           PUT    /                                      members/registrations#update
                           DELETE /                                      members/registrations#destroy
                           POST   /                                      members/registrations#create

应用程序/模型/ member.rb

class Member < ApplicationRecord
  has_one :profile, dependent: :destroy
  has_many :involvements, dependent: :destroy
  has_many :donations

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  accepts_nested_attributes_for :profile

  validates_uniqueness_of :email
end

会员控制器

应用程序/控制器/成员/ sessions_controller.rb

class Members::SessionsController < Devise::SessionsController
  # before_action :configure_sign_in_params, only: [:create]

  # GET /resource/sign_in
  def new
    if params[:return_page]
      session[:member_return_to] = params[:return_page]
    end

    if params[:add_support]
      flash[:warning] = 'You need to login or register for an account first.'
      session[:add_support] = params[:add_support]
      @support = Support.find_by(url_friendly_title: params[:add_support])
      session[:member_return_to] = support_page_path(@support.url_friendly_title)
    end

    if params[:return_page] || params[:add_support]
      redirect_to new_member_session_path
      return
    end

    super
  end

  # POST /resource/sign_in
  # def create
  #   super
  # end

  # DELETE /resource/sign_out
  # def destroy
  #   super
  # end

  # protected

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_sign_in_params
  #   devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
  # end
end

请帮助

您可以提供有关为什么会员的Devise模型未在Heroku上初始化的任何帮助将非常感谢。我忘记了部署时需要更改的设置吗?

1 个答案:

答案 0 :(得分:1)

经过大量研究后,出现这种错误的原因有很多。我将发布解决导致此错误的特定问题的答案,以防将来有人遇到同样的问题。

现在,明天启动我的网站之前修复最后的问题。感谢大家帮助我们追踪问题。

<强>答案:

如果你查看我的问题,sessions_controller.rb就嵌套在&#39;会员&#39;不是&#39;成员&#39;。正如@max在他的澄清评论中指出的那样,我本地计算机上的文件系统不区分大小写,而在生产中它是区分大小写的。所以,这就是为什么&#34;会员&#34;没有初始化。