当我处于开发模式并尝试 localhost:3000/documents/1 时,视图正确呈现并且控制台显示:
Started GET "/documents/1" for 127.0.0.1
Processing by DocumentsController#show as HTML
Parameters: {"id"=>"1"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Document Load (0.3ms) SELECT "documents".* FROM "documents" WHERE "documents"."id" = $1 LIMIT 1 [["id", "1"]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Comment Load (0.4ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = 1 AND "comments"."commentable_type" = 'Document' ORDER BY created_at ASC, created_at DESC
Tag Load (0.4ms) SELECT "tags".* FROM "tags" INNER JOIN "document_tags" ON "tags"."id" = "document_tags"."tag_id" WHERE "document_tags"."document_id" = 1 AND "tags"."tag_family_id" = 1 LIMIT 1
Tag Load (0.4ms) SELECT "tags".* FROM "tags" INNER JOIN "document_tags" ON "tags"."id" = "document_tags"."tag_id" WHERE "document_tags"."document_id" = 1 AND "tags"."tag_family_id" = 2 LIMIT 1
Tag Load (0.7ms) SELECT "tags".* FROM "tags" INNER JOIN "document_tags" ON "tags"."id" = "document_tags"."tag_id" WHERE "document_tags"."document_id" = 1 AND "tags"."tag_family_id" = 3 LIMIT 1
Tag Load (0.5ms) SELECT "tags".* FROM "tags" INNER JOIN "document_tags" ON "tags"."id" = "document_tags"."tag_id" WHERE "document_tags"."document_id" = 1 AND "tags"."tag_family_id" = 4 LIMIT 1
Tag Load (0.3ms) SELECT name FROM "tags" INNER JOIN "document_tags" ON "tags"."id" = "document_tags"."tag_id" WHERE "document_tags"."document_id" = 1 AND "tags"."tag_family_id" = 5
Tag Load (0.3ms) SELECT name FROM "tags" INNER JOIN "document_tags" ON "tags"."id" = "document_tags"."tag_id" WHERE "document_tags"."document_id" = 1 AND "tags"."tag_family_id" = 6
Rating Load (0.4ms) SELECT "ratings".* FROM "ratings" WHERE "ratings"."user_id" = 1 AND "ratings"."document_id" = 1 LIMIT 1
Rendered ratings/_show.html.erb (5.7ms)
Rendered comments/show.html.erb (0.1ms)
Rendered comments/_form.html.erb (1.6ms)
Rendered documents/show.html.erb within layouts/application (113.6ms)
Rendered layouts/_actions_header.html.erb (0.4ms)
Rendered layouts/_header.html.erb (1.5ms)
Rendered layouts/sidebar/_reciente.html.erb (0.1ms)
Rendered layouts/_footer.html.erb (2.6ms)
Completed 200 OK in 159ms (Views: 138.4ms | ActiveRecord: 4.3ms)
但是当我改为生产时,我得到:
Started GET "/documents/1" for 127.0.0.1
Processing by DocumentsController#show as HTML
Parameters: {"id"=>"1"}
User Load (5.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Document Load (1.1ms) SELECT "documents".* FROM "documents" WHERE "documents"."id" = $1 LIMIT 1 [["id", "1"]]
Comment Load (1.4ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = 1 AND "comments"."commentable_type" = 'Document' ORDER BY created_at ASC, created_at DESC
Rendered documents/show.html.erb within layouts/application (7.6ms)
Completed 500 Internal Server Error in 508ms
ActionView::Template::Error (undefined method `username' for nil:NilClass):
13: <%if(!@tags.blank?) %>
14: <label>Palabras Clave:</label> <%=@tags.join(", ")%> <br />
15: <%end%>
16: <label>Un aporte de </label><%= link_to @uploader.username, user_path(@uploader)%>
17:
18: <div id="ratings">
19: <%= render :partial => 'ratings/show', :locals => {:model => @document} %>
app/views/documents/show.html.erb:16:in `_app_views_documents_show_html_erb__1282539740_2502607180'
app/controllers/roles_controller.rb:103:in `show'
应用程序跟踪显示:
app/views/documents/show.html.erb:16:in `_app_views_documents_show_html_erb__1282539740_2502607180'
app/controllers/roles_controller.rb:103:in `show'
为什么最后一行显示 roles_controller.rb:103:in `show' ?不应该是documents_controller.rb吗?如果我通过将变量名称更改为不存在的名称来强制开发错误,则错误页面会显示在应用程序跟踪中:
app/views/documents/show.html.erb:16:in `_app_views_documents_show_html_erb___1159141803_2474953060'
app/controllers/documents_controller.rb:29:in `show'
可以看到最后一行显示了documents_controller.rb。
我真的不知道在哪里看。当我在 production.rb 中将 config.cache_classes = true 设置为 false 时,错误消失了。(我不知道这是什么意思)。也许我不知道如何配置路由。我应该发布我的 routes.rb 文件吗?
任何帮助,将不胜感激!