ActionController :: RoutingError(未初始化的常量CommonWarningsController)

时间:2015-01-26 05:46:57

标签: ruby-on-rails ruby

我在ubuntu机器上编写Ruby on Rails应用程序(rails 4)。

我已经通过rails g scaffold common_warnings创建了一个新的脚手架(模型/视图/控制器),它在我的本地机器上工作正常(localhost:3000 / common_warnings解析为适当的),但是当我上传到我的服务器,我收到此错误:

ActionController::RoutingError (uninitialized constant CommonWarningsController)

试图获取mydomain.com/common_warnings。

我知道有时多元化是一个问题,这些是我的每个控制器和模型文件的第一行:

app / controllers / common_warnings_controller.rb

class CommonWarningsController < ApplicationController

应用程序/模型/ common_warning.rb

class CommonWarning < ActiveRecord::Base

我的rails应用程序已经在数据库中有30个表格,我知道我不久前确实遇到过这个问题,但是无法解决如何解决这个问题。复数似乎与我对loan_histories_controller.rb(也是一个多字名)的作用相匹配。

rake路由的输出在我的本地计算机和服务器上是相同的。这是相关的输出:

rake routes | grep common

common_warnings     GET  /common_warnings(.:format)     common_warnings#index
                    POST /common_warnings(.:format)     common_warnings#create
new_common_warning  GET  /common_warnings/new(.:format) common_warnings#new
edit_common_warning GET  /common_warnings/:id/edit(.:format) common_warnings#edit
 common_warning    GET  /common_warnings/:id(.:format) common_warnings#show
                  PATCH  /common_warnings/:id(.:format) common_warnings#update
                  PUT  /common_warnings/:id(.:format)   common_warnings#update
                  DELETE /common_warnings/:id(.:format)                                      common_warnings#destroy

&#34;服务器&#34;在这种情况下由AWS提供

这是我完整的常​​见警告控制器:

class CommonWarningsController < ApplicationController
  before_action :set_common_warning, only: [:show, :edit, :update, :destroy]
  before_action :signed_in_user
  before_action :admin_user


  # GET /common_warnings
  # GET /common_warnings.json
  def index
    @common_warnings = CommonWarning.all
  end

  # GET /common_warnings/1
  # GET /common_warnings/1.json
  def show
  end

  # GET /common_warnings/new
  def new
    @new_or_edit = 'new'
    @common_warning = CommonWarning.new
  end

  # GET /common_warnings/1/edit
  def edit
    @new_or_edit = 'edit'
  end

  # POST /common_warnings
  # POST /common_warnings.json
  def create
    @common_warning = CommonWarning.new(common_warning_params)

    respond_to do |format|
      if @common_warning.save
        format.html { redirect_to @common_warning, notice: 'Common warning was successfully created.' }
      else
        format.html { render action: 'new' }
      end
    end
  end

  # PATCH/PUT /common_warnings/1
  # PATCH/PUT /common_warnings/1.json
  def update
    respond_to do |format|
      if @common_warning.update(common_warning_params)
        format.html { redirect_to @common_warning, notice: 'Common warning was successfully updated.' }
      else
        format.html { render action: 'edit' }
      end
    end
  end

  # DELETE /common_warnings/1
  # DELETE /common_warnings/1.json
  def destroy
    @common_warning.destroy
    respond_to do |format|
      format.html { redirect_to common_warnings_url }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_common_warning
      @common_warning = CommonWarning.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def common_warning_params
      params.require(:common_warning).permit(:name)
    end

    def signed_in_user
      store_location
      redirect_to signin_url, notice: "Please sign in." unless signed_in?
    end

    def admin_user
      redirect_to(root_url) unless current_user.admin?
    end

end

提前致谢!

1 个答案:

答案 0 :(得分:0)

固定。从一台服务器运行多个相似但不相同的rails应用程序是一个复杂的问题。我忘记重置与架构迁移的连接。感谢那些回复的人!