当我处于开发模式并尝试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'
为什么最后一行显示的是role_controller.rb:103:在`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文件吗?
任何帮助将不胜感激!
答案 0 :(得分:0)
我刚刚发现roles_controllers有一个document_controller的部分定义,当在生产中缓存时,它是第一个被调用的。我刚删除了角色控制器中的documents_controller的部分定义,并将所有内容移动到了正确的控制器。