[英]Rails uninitialized constant error
在我的開發環境中,頁面可以正常加載。 在生產中,出現此錯誤:
NameError(未初始化的常量EventTypesController :: EventType):app / controllers / event_types_controller.rb:3:在“索引”中
這是我的控制器:
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>
知道我在做什么錯嗎?
當我在生產控制台中鍵入EventType時,將發生以下情況:
irb(main):004:0> EventType NameError:來自/home/deploy/track/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails中(irb):4的未初始化常量EventType
start' from /home/deploy/track/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in
“從/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中! 來自/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'來自bin / rails
ByeBug結果:
EventType EventType EventType(id:整數,描述:字符串,created_at:日期時間,Updated_at:日期時間)(byebug)
可能在開發而不是生產中找到EventType
表。
您是否已成功將EventType
表遷移到生產環境?
$ bin/rails db:migrate RAILS_ENV=production
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.