開発モードで 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'
`show' で最後の行に roles_controller.rb:103: が表示されるのはなぜですか? 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 ファイルを投稿する必要がありますか?
どんな助けでも大歓迎です!