2016-06-22 20 views
0

私の開発環境では、ページが正常に読み込まれます。生産では、私はこのエラーを取得する:ここでRails初期化されていない定数エラー

NameError (uninitialized constant EventTypesController::EventType): app/controllers/event_types_controller.rb:3:in `index'

は私のコントローラです:

class EventTypesController < ApplicationController 
    def index 
    @event_types = EventType.all 
    end 

    def update_event_type 
    event_type = EventType.find_by_id(params[:id]) 
    if event_type.update(event_type_params) 
     flash[:notice] = 'Event Type Updated' 
     redirect_to :action => :index 
    end 
    end 

    def create_event_type 
    event_type = EventType.new(event_type_params) 
    if event_type.save 
     flash[:notice] = 'Event Type Created' 
     redirect_to :action => :index 
    end 
    end 

    def destroy_event_type 
    event_type = EventType.find_by_id(params[:id]) 
    if event_type.destroy 
     flash[:notice] = 'Event Type Deleted' 
     redirect_to :action => :index 
    end 
    end 

    def event_type_params 
    params.require('eventtype').permit('description') 
    end 
end 

ここに私のビューです:

<h1>Event Types</h1> 

<table> 
    <tr> 
    <th>Event Type Description</th> 
    <th></th> 
    </tr> 
    <% @event_types.each do |eventtype| %> 
    <% if params[:edit] && params[:edit] == eventtype.id.to_s %> 
     <tr> 
     <%=form_for :eventtype, :url => {:action => 'update_event_type', :id => eventtype } do |form| -%> 
      <td><%= form.text_field :description %></td> 
      <td><%= submit_tag("Update") %> 
      <%= link_to 'Cancel', {:action => :index} %></td> 
     <%end%> 
     </tr> 
     <%else%> 
     <tr> 
      <td><%= eventtype.description %></td> 
      <td><%=link_to "Edit", {:edit => eventtype.id} %> 
      <%=link_to "Delete", {:action => 'destroy_event_type', :id => eventtype.id},:method => :delete ,data: {confirm:'Are you sure you want to delete this event type?'} %></td> 
     </tr> 
    <%end%> 
    <%end%> 
    <% if !params[:edit] %> 
     <%=form_for :eventtype, :url => {:action => 'create_event_type' } do |form| -%> 
     <tr> 
      <td><%= form.text_field :description %></td> 
      <td><%= submit_tag("Add Event Type") %></td> 
     </tr> 
     <%end%> 
    <%end%> 
</table> 

私が間違っているの何任意のアイデア?

これは私が生産コンソールにイベントタイプを入力するときに何が起こるかです:

irb(main):004:0> EventType NameError: uninitialized constant EventType from (irb):4 from /home/deploy/track/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in start' from /home/deploy/track/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in start' from /home/deploy/track/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in console' from /home/deploy/track/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in run_command!' from /home/deploy/track/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in <top (required)>' from bin/rails:4:in require' from bin/rails

ByeBug結果:

EventType EventType EventType(id: integer, description: string, created_at: datetime, updated_at: datetime) (byebug)

+0

生産コードは最新のものですか?本番環境で 'rake db:migrate'を実行しましたか? – mmichael

+0

はい、私は、テーブルがMySQLで作成されたことを確認しました。また、SQLを使用して手動でレコードを追加しました。 –

+0

それは奇妙です。デバッガ(例:byebug)を使用してインデックスアクションを検査し、 'EventType'クラスが定義されていることを確認することをお勧めします。コードとdbが最新のものであれば、ローカルでは動作しません。 – mmichael

答えて

0

おそらくEventTypeテーブルは、開発ではなく、生産に発見されました。

EventTypeテーブルを本番環境に移行しましたか?

$ bin/rails db:migrate RAILS_ENV=production 
+0

私はdb:migrate for productionを複数回実行しており、テーブルは本番環境に存在しています –

関連する問題