更新:显然我的资产管道出现了一些问题;我的资产没有被预编译,导致500错误。我已经发布了一些关于我如何解决它的细节。
我知道在StackOverflow和其他地方有几个关于此的问题,但我现在已经为这个问题苦苦挣扎了一天,到目前为止我还没有找到解决方案。
这是我的问题:我的rails应用程序一直给我一个错误500(“我们很抱歉,但出了问题。”)我在服务器上安装了rvm,apache和passenger命令尝试托管rails应用程序(全部安装为sudo)。我已成功按照phusion主页上的安装说明进行操作,但是当需要将它链接到我的rails应用程序时,我遇到了很多问题。
以下是该问题的一些相关信息:
我的应用程序的根目录位于/ srv / myappname
我的development.log文件显示以下输出:
Started GET "/messages" for 127.0.0.1 at 2013-07-16 15:05:15 -0400 Processing by MessagesController#index as HTML User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]] Message Load (0.0ms) SELECT "messages".* FROM "messages" WHERE "messages"."to_user_id" = 2 User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]] (0.0ms) SELECT COUNT(*) FROM "messages" WHERE "messages"."to_user_id" = 2 Rendered messages/index.html.erb within layouts/application (3.0ms) Completed 500 Internal Server Error in 24ms RuntimeError - 2: app/views/messages/index.html.erb:17:in `block in _app_views_messages_index_html_erb__568106274_50485404' app/views/messages/index.html.erb:16:in `_app_views_messages_index_html_erb__568106274_50485404' actionpack (3.2.8) lib/action_view/template.rb:145:in `block in render' activesupport (3.2.8) lib/active_support/notifications.rb:125:in `instrument' actionpack (3.2.8) lib/action_view/template.rb:143:in `render' actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template' actionpack (3.2.8) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument' activesupport (3.2.8) lib/active_support/notifications.rb:123:in `block in instrument' activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (3.2.8) lib/active_support/notifications.rb:123:in `instrument' actionpack (3.2.8) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument' actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template' actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout' actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:45:in `render_template' actionpack (3.2.8) lib/action_view/renderer/template_renderer.rb:18:in `render' actionpack (3.2.8) lib/action_view/renderer/renderer.rb:36:in `render_template' actionpack (3.2.8) lib/action_view/renderer/renderer.rb:17:in `render' actionpack (3.2.8) lib/abstract_controller/rendering.rb:110:in `_render_template' actionpack (3.2.8) lib/action_controller/metal/streaming.rb:225:in `_render_template' actionpack (3.2.8) lib/abstract_controller/rendering.rb:103:in `render_to_body' actionpack (3.2.8) lib/action_controller/metal/renderers.rb:28:in `render_to_body' actionpack (3.2.8) lib/action_controller/metal/compatibility.rb:50:in `render_to_body' actionpack (3.2.8) lib/abstract_controller/rendering.rb:88:in `render' actionpack (3.2.8) lib/action_controller/metal/rendering.rb:16:in `render' actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render' activesupport (3.2.8) lib/active_support/core_ext/benchmark.rb:5:in `block in ms' C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/benchmark.rb:295:in `realtime' activesupport (3.2.8) lib/active_support/core_ext/benchmark.rb:5:in `ms' actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:40:in `block in render' actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime' activerecord (3.2.8) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime' actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:39:in `render' actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:10:in `default_render' actionpack (3.2.8) lib/action_controller/metal/mime_responds.rb:196:in `respond_to' app/controllers/messages_controller.rb:21:in `index' actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action' actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action' actionpack (3.2.8) lib/action_controller/metal/rendering.rb:10:in `process_action' actionpack (3.2.8) lib/abstract_controller/callbacks.rb:18:in `block in process_action' activesupport (3.2.8) lib/active_support/callbacks.rb:425:in `_run__105841733__process_action__861948368__callbacks' activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.2.8) lib/abstract_controller/callbacks.rb:17:in `process_action' actionpack (3.2.8) lib/action_controller/metal/rescue.rb:29:in `process_action' actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' activesupport (3.2.8) lib/active_support/notifications.rb:123:in `block in instrument' activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (3.2.8) lib/active_support/notifications.rb:123:in `instrument' actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:29:in `process_action' actionpack (3.2.8) lib/action_controller/metal/params_wrapper.rb:207:in `process_action' activerecord (3.2.8) lib/active_record/railties/controller_runtime.rb:18:in `process_action' actionpack (3.2.8) lib/abstract_controller/base.rb:121:in `process' actionpack (3.2.8) lib/abstract_controller/rendering.rb:45:in `process' actionpack (3.2.8) lib/action_controller/metal.rb:203:in `dispatch' actionpack (3.2.8) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' actionpack (3.2.8) lib/action_controller/metal.rb:246:in `block in action' actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `call' actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `dispatch' actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:36:in `call' journey (1.0.4) lib/journey/router.rb:68:in `block in call' journey (1.0.4) lib/journey/router.rb:56:in `each' journey (1.0.4) lib/journey/router.rb:56:in `call' actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:600:in `call' omniauth (1.1.3) lib/omniauth/strategy.rb:394:in `call_app!' omniauth-identity (1.1.0) lib/omniauth/strategies/identity.rb:36:in `other_phase' omniauth (1.1.3) lib/omniauth/strategy.rb:176:in `call!' omniauth (1.1.3) lib/omniauth/strategy.rb:157:in `call' omniauth (1.1.3) lib/omniauth/strategy.rb:177:in `call!' omniauth (1.1.3) lib/omniauth/strategy.rb:157:in `call' omniauth (1.1.3) lib/omniauth/strategy.rb:177:in `call!' omniauth (1.1.3) lib/omniauth/strategy.rb:157:in `call' omniauth (1.1.3) lib/omniauth/builder.rb:48:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' rack (1.4.5) lib/rack/etag.rb:23:in `call' rack (1.4.5) lib/rack/conditionalget.rb:25:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/head.rb:14:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/params_parser.rb:21:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/flash.rb:242:in `call' rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context' rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/cookies.rb:339:in `call' activerecord (3.2.8) lib/active_record/query_cache.rb:64:in `call' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `_run__19373668__call__508978036__callbacks' activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:65:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call' better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call' better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app' railties (3.2.8) lib/rails/rack/logger.rb:16:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call' rack (1.4.5) lib/rack/methodoverride.rb:21:in `call' rack (1.4.5) lib/rack/runtime.rb:17:in `call' activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.4.5) lib/rack/lock.rb:15:in `call' actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call' railties (3.2.8) lib/rails/engine.rb:479:in `call' railties (3.2.8) lib/rails/application.rb:223:in `call' rack (1.4.5) lib/rack/content_length.rb:14:in `call' railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call' thin (1.5.1) lib/thin/connection.rb:81:in `block in pre_process' thin (1.5.1) lib/thin/connection.rb:79:in `catch' thin (1.5.1) lib/thin/connection.rb:79:in `pre_process' thin (1.5.1) lib/thin/connection.rb:54:in `process' thin (1.5.1) lib/thin/connection.rb:39:in `receive_data' eventmachine-1.0.3-x86 (mingw32) lib/eventmachine.rb:187:in `run_machine' eventmachine-1.0.3-x86 (mingw32) lib/eventmachine.rb:187:in `run' thin (1.5.1) lib/thin/backends/base.rb:63:in `start' thin (1.5.1) lib/thin/server.rb:159:in `start' rack (1.4.5) lib/rack/handler/thin.rb:13:in `run' rack (1.4.5) lib/rack/server.rb:268:in `start' railties (3.2.8) lib/rails/commands/server.rb:70:in `start' railties (3.2.8) lib/rails/commands.rb:55:in `block in ' railties (3.2.8) lib/rails/commands.rb:50:in `tap' railties (3.2.8) lib/rails/commands.rb:50:in `' script/rails:6:in `require' script/rails:6:in `' Started POST "/__better_errors/51402684/variables" for 127.0.0.1 at 2013-07-16 15:05:15 -0400 Started GET "/messages" for 127.0.0.1 at 2013-07-16 15:05:29 -0400 Processing by MessagesController#index as HTML User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]] Message Load (1.0ms) SELECT "messages".* FROM "messages" WHERE "messages"."to_user_id" = 2 User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]] (0.0ms) SELECT COUNT(*) FROM "messages" WHERE "messages"."to_user_id" = 2 Rendered messages/index.html.erb within layouts/application (3.0ms) Category Load (0.0ms) SELECT "categories".* FROM "categories" Location Load (0.0ms) SELECT "locations".* FROM "locations" Rendered shared/_create_project.html.erb (26.0ms) CACHE (0.0ms) SELECT "categories".* FROM "categories" CACHE (0.0ms) SELECT "locations".* FROM "locations" Rendered shared/_create_project.html.erb (3.0ms) Rendered shared/_header.html.erb (32.0ms) Rendered shared/_footer.html.erb (0.0ms) Rendered shared/_login-modal.html.erb (1.0ms) Completed 200 OK in 88ms (Views: 85.3ms | ActiveRecord: 1.0ms) ...
我的/etc/apache2/sites-available/dev.myappname.com文件已启用,服务器已重新启动,并且包含以下信息:
ServerName dev.myappname.com DocumentRoot / srv / myappname / public 选项-MultiViews -Indexes 允许所有人 PassengerResolveSymlinksInDocumentRoot on RailsBaseURI / myappname
这是我的app / views / messages / index.html.erb,它在错误中提及(几乎是rails默认值):
<h1>Listing messages</h1>
<table>
<tr>
<th>From user</th>
<th>Subject</th>
<th>Message</th>
<th>Replied</th>
<th></th>
<th></th>
<th></th>
</tr>
<% if @messages.count > 0 %>
<% @messages.each do |message| %>
<tr>
<td><%= link_to @users[message.from_user_id].display_name, user_url(message.from_user_id) %></td>
<td><%= message.subject %></td>
<td><%= message.message %></td>
<td><%= message.replied %></td>
<td><%= message.project_id %></td>
<td><%= link_to 'Show', message %></td>
<td><%= link_to 'Edit', edit_message_path(message) %></td>
<td><%= link_to 'Destroy', message, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
<% else %>
<tr><td colspan="7"><i>No messages yet!</i></td></tr>
<% end %>
</table>
<br />
<%= link_to 'New Message', new_message_path %>
这是我的消息#index:
def index
# only run this page if signed in
if signed_in? == false
redirect_to root_url
return
end
@messages = Message.where(:to_user_id => current_user.id)
@users = {}
@messages.each do |msg|
user = User.find(msg.from_user_id)
@users[user.id] = user
end
#@messages = Message.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @messages }
end
end
我的大多数资产(scss,js和图像文件)都位于我的rails应用程序的/ app / assets文件夹中,而不是公共资源。我查看了日志中的运行时错误,但我无法理解它。它也可以在本地完美运行。
有没有人对我做错了什么有任何想法?
答案 0 :(得分:0)
显然我收到了500错误,因为我的资产没有预编译;我看了一下/var/log/apache2/error.log,得到了很多以下类型的输出:
[ 2013-07-18 15:52:14.4139 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] ActionView::Template::Error (login_icons/facebook.png isn't precompiled):
[ 2013-07-18 15:52:14.4139 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] 9: <h3>
[ 2013-07-18 15:52:14.4140 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] 10: Log in with
[ 2013-07-18 15:52:14.4140 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] 11: </h3>
[ 2013-07-18 15:52:14.4140 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] 12: <%= link_to image_tag('login_icons/facebook.png'), '/auth/facebook', class: 'facebook' %>
[ 2013-07-18 15:52:14.4140 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] 13: <%= link_to image_tag('login_icons/linkedin.png'), '/auth/linkedin', class: 'linkedin' %>
[ 2013-07-18 15:52:14.4140 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] 14:
[ 2013-07-18 15:52:14.4140 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] 15: </div>
[ 2013-07-18 15:52:14.4140 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] app/views/index/_login.html.erb:12:in `block in _app_views_index__login_html_erb___198542020543089497_28595940'
[ 2013-07-18 15:52:14.4141 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] app/views/index/_login.html.erb:7:in `_app_views_index__login_html_erb___198542020543089497_28595940'
[ 2013-07-18 15:52:14.4141 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] app/views/index/index.html.erb:13:in `_app_views_index_index_html_erb___1644088413939532220_28016960'
[ 2013-07-18 15:52:14.4141 26976/7f6ee2809700 Pool2/Implementation.cpp:1182 ]: [App 27049 stderr] app/controllers/index_controller.rb:13:in `index'
我仍然需要弄清楚如何让apache识别我的资产位置,但在短期内,手动预编译我的资产使用以下命令:
rake assets:precompile --trace RAILS_ENV=production
service apache2 restart