2016-03-09 67 views
0

當我在開發中本地運行它時,我可以很好地查看所有用戶和每個用戶。Rails在Heroku中缺少模板用戶/顯示和用戶/索引

當我嘗試查看所有用戶或從我的側邊欄Heroku服務器部分特定的用戶,我得到一個丟失的模板錯誤,即使我有兩個users/indexusers/show

在StackOverflow上進行了一些搜索之後,我意識到我擁有的用戶文件夾實際上是'用戶',並帶有大寫的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的日誌:

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 
+0

我想你忘了把適當的文件推送到heroku。但是如果沒有看到日誌就很難說清楚。 –

+0

你的意思是'git push heroku master'之後的日誌嗎? –

+0

顯示heroku日誌:'$ heroku日誌' – uday

回答

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安裝)?