Rails仅在Heroku上缺少模板用户/ show和users / index

时间:2016-03-09 00:19:18

标签: ruby-on-rails heroku devise

当我在开发中本地运行时,我可以完全正常地查看所有用户和每个用户。

当我尝试从Heroku服务器上的侧边栏部分查看所有用户或特定用户时,即使我同时拥有users/indexusers/show,我也会收到错误的模板错误。< / p>

在对StackOverflow进行一些搜索之后,我意识到我拥有的用户文件夹实际上是用户&#39;用大写的u。我想在将文件夹重命名为users之后我的问题就会解决,但它仍然是一样的。

布局/ _sidebar.html.erb:

<% if user_signed_in? -%>
        <li><%= link_to(current_user) do |profile| %>
        <i class="glyphicon glyphicon-user"></i> My Profile
        <% end %>
        </li>
    <% end %>
    <li><%= link_to(users_path) do |users| %>
        <i class="glyphicon glyphicon-eye-open"></i> All Users
    <% end %>
    </li>

用户/ index.html.erb

<h1>All Users</h1>
<% @users.order("name ASC").each do |user| %>
    <div class="clip row clearfix">
        <div class="container">
            <h2>
            <%= link_to user.name, user %>
            </h2>
        </div>
    </div>
<% end %>

控制器/ users_controller.rb

class UsersController < ApplicationController
    before_action :signed_in?, only: [:index, :edit, :update, :destroy,
                                        :following, :followers]

    def create
        @user = User.new(params[:user])
        if @user.save
          UserMailer.welcome_email(@user).deliver_now
        end
    end

    def index
      @users = User.all
    end

    def show
      @user = User.find(params[:id])
    end

    def following
      @title = "Following"
      @user  = User.find(params[:id])
      @users = @user.following(page: params[:page])
      render 'show_follow'
    end

    def followers
      @title = "Followers"
      @user  = User.find(params[:id])
      @users = @user.followers(page: params[:page])
      render 'show_follow'
    end
end

$ heroku logs:

2016-03-09T01:12:10.995780+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/core_ext/benchmark.rb:12:in `ms'
2016-03-09T01:12:10.995780+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/instrumentation.rb:44:in `block in render'
2016-03-09T01:12:10.995781+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
2016-03-09T01:12:10.995782+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_rec
ord/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
2016-03-09T01:12:10.995783+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/instrumentation.rb:43:in `render'
2016-03-09T01:12:10.995783+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/implicit_render.rb:10:in `default_render'
2016-03-09T01:12:10.995784+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/implicit_render.rb:5:in `send_action'
2016-03-09T01:12:10.995785+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/abstract_con
troller/base.rb:198:in `process_action'
2016-03-09T01:12:10.995785+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/rendering.rb:10:in `process_action'
2016-03-09T01:12:10.995786+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/abstract_con
troller/callbacks.rb:20:in `block in process_action'
2016-03-09T01:12:10.995787+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:117:in `call'
2016-03-09T01:12:10.995788+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:117:in `call'
2016-03-09T01:12:10.995789+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:505:in `call'
2016-03-09T01:12:10.995788+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:555:in `block (2 levels) in compile'
2016-03-09T01:12:10.995790+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:505:in `call'
2016-03-09T01:12:10.995796+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/abstract_con
troller/callbacks.rb:19:in `process_action'
2016-03-09T01:12:10.995796+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/rescue.rb:29:in `process_action'
2016-03-09T01:12:10.995790+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:92:in `__run_callbacks__'
2016-03-09T01:12:10.995795+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:81:in `run_callbacks'
2016-03-09T01:12:10.995791+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:778:in `_run_process_action_callbacks'
2016-03-09T01:12:10.995802+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/instrumentation.rb:32:in `block in process_action'
2016-03-09T01:12:10.995803+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/notifications.rb:164:in `block in instrument'
2016-03-09T01:12:10.995804+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/notifications/instrumenter.rb:20:in `instrument'
2016-03-09T01:12:10.995804+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/notifications.rb:164:in `instrument'
2016-03-09T01:12:10.995805+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/instrumentation.rb:30:in `process_action'
2016-03-09T01:12:10.995805+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/params_wrapper.rb:250:in `process_action'
2016-03-09T01:12:10.995806+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_rec
ord/railties/controller_runtime.rb:18:in `process_action'
2016-03-09T01:12:10.995814+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/abstract_con
troller/base.rb:137:in `process'
2016-03-09T01:12:10.995815+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionview-4.2.5/lib/action_view/
rendering.rb:30:in `process'
2016-03-09T01:12:10.995815+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal.rb:196:in `dispatch'
2016-03-09T01:12:10.995816+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal/rack_delegation.rb:13:in `dispatch'
2016-03-09T01:12:10.995817+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_contr
oller/metal.rb:237:in `block in action'
2016-03-09T01:12:10.995818+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/routing/route_set.rb:76:in `dispatch'
2016-03-09T01:12:10.995817+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/routing/route_set.rb:76:in `call'
2016-03-09T01:12:10.995818+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/routing/route_set.rb:45:in `serve'
2016-03-09T01:12:10.995819+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/journey/router.rb:43:in `block in serve'
2016-03-09T01:12:10.995820+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/journey/router.rb:30:in `each'
2016-03-09T01:12:10.995821+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/routing/route_set.rb:817:in `call'
2016-03-09T01:12:10.995820+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/journey/router.rb:30:in `serve'
2016-03-09T01:12:10.995821+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/warden-1.2.6/lib/warden/manager.r
b:35:in `block in call'
2016-03-09T01:12:10.995824+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/etag.rb:24:in
 `call'
2016-03-09T01:12:10.995822+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/warden-1.2.6/lib/warden/manager.r
b:34:in `catch'
2016-03-09T01:12:10.995823+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/warden-1.2.6/lib/warden/manager.r
b:34:in `call'
2016-03-09T01:12:10.995824+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/conditionalge
t.rb:25:in `call'
2016-03-09T01:12:10.995825+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/head.rb:13:in
 `call'
2016-03-09T01:12:10.995826+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/flash.rb:260:in `call'
2016-03-09T01:12:10.995828+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/session/abstr
act/id.rb:220:in `call'
2016-03-09T01:12:10.995826+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/params_parser.rb:27:in `call'
2016-03-09T01:12:10.995827+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/session/abstr
act/id.rb:225:in `context'
2016-03-09T01:12:10.995828+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/cookies.rb:560:in `call'
2016-03-09T01:12:10.995830+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_rec
ord/connection_adapters/abstract/connection_pool.rb:653:in `call'
2016-03-09T01:12:10.995829+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_rec
ord/query_cache.rb:36:in `call'
2016-03-09T01:12:10.995833+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/callbacks.rb:29:in `block in call'
2016-03-09T01:12:10.995834+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:88:in `__run_callbacks__'
2016-03-09T01:12:10.995835+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:778:in `_run_call_callbacks'
2016-03-09T01:12:10.995835+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/callbacks.rb:81:in `run_callbacks'
2016-03-09T01:12:10.995839+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/callbacks.rb:27:in `call'
2016-03-09T01:12:10.995839+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/remote_ip.rb:78:in `call'
2016-03-09T01:12:10.995840+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/debug_exceptions.rb:17:in `call'
2016-03-09T01:12:10.995841+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/show_exceptions.rb:30:in `call'
2016-03-09T01:12:10.995841+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/rack/log
ger.rb:38:in `call_app'
2016-03-09T01:12:10.995843+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/tagged_logging.rb:68:in `block in tagged'
2016-03-09T01:12:10.995844+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/tagged_logging.rb:68:in `tagged'
2016-03-09T01:12:10.995845+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/request_id.rb:21:in `call'
2016-03-09T01:12:10.995843+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/tagged_logging.rb:26:in `tagged'
2016-03-09T01:12:10.995842+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/rack/log
ger.rb:20:in `block in call'
2016-03-09T01:12:10.995845+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/rack/log
ger.rb:20:in `call'
2016-03-09T01:12:10.995847+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/runtime.rb:18
:in `call'
2016-03-09T01:12:10.995847+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_su
pport/cache/strategy/local_cache_middleware.rb:28:in `call'
2016-03-09T01:12:10.995848+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispa
tch/middleware/static.rb:116:in `call'
2016-03-09T01:12:10.995846+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/methodoverrid
e.rb:22:in `call'
2016-03-09T01:12:10.995848+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/sendfile.rb:1
13:in `call'
2016-03-09T01:12:10.995849+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/engine.r
b:518:in `call'
2016-03-09T01:12:10.995850+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/applicat
ion.rb:165:in `call'
2016-03-09T01:12:10.995851+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/content_lengt
h.rb:15:in `call'
2016-03-09T01:12:10.995852+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/handler/webri
ck.rb:88:in `service'
2016-03-09T01:12:10.995851+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in
 `call'
2016-03-09T01:12:10.995852+00:00 app[web.1]:   vendor/ruby-2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `
service'
2016-03-09T01:12:10.995853+00:00 app[web.1]:   vendor/ruby-2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `r
un'
2016-03-09T01:12:10.995854+00:00 app[web.1]:   vendor/ruby-2.2.4/lib/ruby/2.2.0/webrick/server.rb:294:in `bloc
k in start_thread'
2016-03-09T01:12:10.995854+00:00 app[web.1]:
2016-03-09T01:12:10.995855+00:00 app[web.1]:
2016-03-09T01:12:11.164436+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/act
ion_dispatch/middleware/templates/rescues/_source.erb (19.5ms)
2016-03-09T01:12:11.179575+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/act
ion_dispatch/middleware/templates/rescues/_trace.html.erb (8.3ms)
2016-03-09T01:12:11.189522+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/act
ion_dispatch/middleware/templates/rescues/_request_and_response.html.erb (3.4ms)
2016-03-09T01:12:11.189608+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/act
ion_dispatch/middleware/templates/rescues/missing_template.html.erb within rescues/layout (51.9ms)
2016-03-09T01:12:11.199828+00:00 heroku[router]: at=info method=GET path="/users" host=clip-share.herokuapp.co
m request_id=bf12ff50-ccbb-43bc-9304-463d839484ec fwd="109.255.231.125" dyno=web.1 connect=0ms service=222ms s
tatus=500 bytes=122404

1 个答案:

答案 0 :(得分:0)

看起来日志有点不完整,无法真正帮助诊断问题。您可以使用heroku logs -t来拖尾日志,并在整个错误出现时停止它们。

您发布的内容还有几点需要注意:

   link_to(user_path(current_user))

您需要将路径助手(user_path)添加到link_to帮助程序,并将当前用户对象传递给侧边栏部分中的路径助手。

虽然它无法解决此问题,但我还建议将.order("name ASC")放在控制器的索引操作中,而不是放在视图中。我假设您的观看代码为app/views/users/

此外,我可以看到您使用Webrick作为您的网络服务器。 Heroku几乎其他所有人都建议不要使用这个网络服务器 - 据我所知,它甚至不会附带即将推出的Rails 5版本。请改用Puma

您的代码最后还有一点不清楚:如果没有用户(没有新的Heroku安装),会发生什么?