1

更新:显然我的资产管道存在一些问题;我的资产没有被预编译,这导致了 500 错误。我在下面发布了一些关于如何解决它的详细信息。


我知道在 StackOverflow 和其他地方有几个关于这个的问题,但是我已经为这个问题苦苦挣扎了大约一天,到目前为止我还没有找到解决方案。

这是我的问题:我的 rails 应用程序不断向我抛出错误 500(“我们很抱歉,但出了点问题。”)我在我的服务器上安装了 rvm、apache 和乘客,以便尝试托管一个 rails 应用程序(全部安装作为须藤)。我已经成功地按照 phusion 主页上的安装说明进行操作,但是当需要将其链接到我的 rails 应用程序时,我遇到了很多问题。

以下是该问题的一些相关信息:

  • 我的应用程序的根目录在 /srv/myappname

  • 我的 development.log 文件显示以下输出:

    在 2013-07-16 15:05:15 -0400 开始为 127.0.0.1 获取“/messages”
    MessagesController#index 处理为 HTML
      用户负载 (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? 限制 1 [["id", 2]]
      消息加载 (0.0ms) SELECT "messages".* FROM "messages" WHERE "messages"."to_user_id" = 2
      用户负载 (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? 限制 1 [["id", 1]]
       (0.0ms) SELECT COUNT(*) FROM "messages" WHERE "messages"."to_user_id" = 2
      在布局/应用程序中渲染消息/index.html.erb (3.0ms)
    在 24 毫秒内完成 500 内部服务器错误

    运行时错误 - 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/instrument.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/instrument.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'
      旅程 (1.0.4) lib/journey/router.rb:68:in `block in call'
      旅程 (1.0.4) lib/journey/router.rb:56:in `each'
      旅程 (1.0.4) lib/journey/router.rb:56:in `call'
      actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:600:in `call'
      omn​​iauth (1.1.3) lib/omniauth/strategy.rb:394:in `call_app!'
      omn​​iauth-identity (1.1.0) lib/omniauth/strategies/identity.rb:36:in `other_phase'
      omn​​iauth (1.1.3) lib/omniauth/strategy.rb:176:in `call!'
      omn​​iauth (1.1.3) lib/omniauth/strategy.rb:157:in `call'
      omn​​iauth (1.1.3) lib/omniauth/strategy.rb:177:in `call!'
      omn​​iauth (1.1.3) lib/omniauth/strategy.rb:157:in `call'
      omn​​iauth (1.1.3) lib/omniauth/strategy.rb:177:in `call!'
      omn​​iauth (1.1.3) lib/omniauth/strategy.rb:157:in `call'
      omn​​iauth (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'
      机架 (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'
      瘦 (1.5.1) lib/thin/connection.rb:81:in `block in pre_process'
      瘦 (1.5.1) lib/thin/connection.rb:79:in `catch'
      瘦 (1.5.1) lib/thin/connection.rb:79:in `pre_process'
      瘦 (1.5.1) lib/thin/connection.rb:54:in `process'
      瘦 (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'
      瘦 (1.5.1) lib/thin/backends/base.rb:63:in `start'
      瘦 (1.5.1) lib/thin/server.rb:159:in `start'
      机架 (1.4.5) lib/rack/handler/thin.rb:13:in `run'
      机架 (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 `'
      脚本/rails:6:in `require'
      脚本/rails:6:in `'

      在 2013-07-16 15:05:15 -0400 为 127.0.0.1 开始 POST "/__better_errors/51402684/variables"

      2013-07-16 15:05:29 -0400 开始为 127.0.0.1 获取“/messages”
      MessagesController#index 处理为 HTML
      用户负载 (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? 限制 1 [["id", 2]]
      消息加载 (1.0ms) SELECT "messages".* FROM "messages" WHERE "messages"."to_user_id" = 2
      用户负载 (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? 限制 1 [["id", 1]]
       (0.0ms) SELECT COUNT(*) FROM "messages" WHERE "messages"."to_user_id" = 2
      在布局/应用程序中渲染消息/index.html.erb (3.0ms)
      类别负载 (0.0ms) SELECT "categories".* FROM "categories"
      位置负载 (0.0ms) SELECT "locations".* FROM "locations"
      渲染 shared/_create_project.html.erb (26.0ms)
      CACHE (0.0ms) SELECT "categories".* FROM "categories"
      CACHE (0.0ms) SELECT "locations".* FROM "locations"
      渲染 shared/_create_project.html.erb (3.0ms)
      渲染 shared/_header.html.erb (32.0ms)
      渲染 shared/_footer.html.erb (0.0ms)
      渲染 shared/_login-modal.html.erb (1.0ms)
    在 88 毫秒内完成 200 次 OK(查看次数:85.3 毫秒 | ActiveRecord:1.0 毫秒)

    ...

  • 我的 /etc/apache2/sites-available/dev.myappname.com 文件已启用,服务器已重新启动,它具有以下信息:

    ServerName dev.myappname.com DocumentRoot /srv/myappname/public Options -MultiViews -Indexes Allow from all 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 文件夹中,而不是公共文件夹中。我查看了日志中的运行时错误,但我无法理解它。它在本地也能完美运行。

有人对我做错了什么有任何想法吗?

4

1 回答 1

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
于 2013-07-18T16:13:38.147 回答