0

我有一個Rails應用程序中用戶索引頁面上的用戶列表,其想法是登錄的用戶可以通過單擊其名稱旁邊的「Start Friendship」按鈕與另一個用戶開始友誼。這爲友誼表添加了一條記錄。在Rails上尋找Heroku視圖的POST/DELETE請求。在本地完美工作

該過程在本地託管時運行良好。該公司使用的SQLite(雖然我不認爲這是一個數據庫的問題)和日誌看起來是這樣的:

Started POST "/friendships" for 127.0.0.1 at 2013-01-25 12:48:16 +0000 
Processing by FriendshipsController#create as HTML 
Parameters: {"utf8"=>"✓", "authenticity_token"=>"P5qQAuaSD1SNkgLDI6yQ2h9GhJjAub7l7On3+ZGBwiY=", "friendship"=>{"befriended_id"=>"16"}, "commit"=>"Start Friendship"} 
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'eL_PfKhO9ZnYTxXTPo9UiQ' LIMIT 1 
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "16"]] 
(0.0ms) begin transaction 
SQL (0.6ms) INSERT INTO "friendships" ("befriended_id", "befriender_id", "confirmed", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["befriended_id", 1], ["befriender_id", 16], ["confirmed", false], ["created_at", Fri, 25 Jan 2013 12:48:16 UTC +00:00], ["updated_at", Fri, 25 Jan 2013 12:48:16 UTC +00:00]] 
(1.4ms) commit transaction 
Redirected to http://localhost:3000/users 
Completed 302 Found in 9ms (ActiveRecord: 2.3ms) 

然而,當我做同樣的我已經在Heroku上託管的應用程序的版本(使用PostgreSQL ),我得到臭名昭着的「我們很抱歉,但出了問題(500)」的錯誤。縱觀日誌,似乎它正在尋找一種不存在的視圖,但我不知道爲什麼它正在尋找它。這裏是日誌:

2013-01-25T12:45:39+00:00 app[web.1]: Started POST "/friendships" for 79.97.21.43 at 2013-01-25 12:45:39 +0000 
2013-01-25T12:45:39+00:00 heroku[router]: at=info method=POST path=/friendships host=meetflag.herokuapp.com fwd=79.97.21.43 dyno=web.1 queue=0 wait=0ms connect=1ms service=135ms status=500 bytes=643 
2013-01-25T12:45:39+00:00 app[web.1]: 
2013-01-25T12:45:39+00:00 app[web.1]: ActionView::MissingTemplate (Missing template friendships/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: 
2013-01-25T12:45:39+00:00 app[web.1]: * "/app/app/views" 
2013-01-25T12:45:39+00:00 app[web.1]:): 

--- (then there's the list of where it's looked) --- 

2013-01-25T12:45:39+00:00 app[web.1]: Processing by FriendshipsController#create as HTML 
2013-01-25T12:45:39+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"n+LI+Br3ahg5FxhNUm2u0b5YcqZGKpfeK7c3vJLkMyU=", "friendship"=>{"befriended_id"=>"2"}, "commit"=>"Start Friendship"} 
2013-01-25T12:45:39+00:00 app[web.1]: Completed 500 Internal Server Error in 86ms 

它甚至似乎沒有得到儘可能遠的數據庫。我試過將資產中的咖啡軌道寶石移動到Gemfile的主體中(正如here所述),根本沒有haml寶石(如提到here),我的Rake數據庫似乎是正確的提到here)。

的友誼控制器看起來是這樣的:

class FriendshipsController < ApplicationController 
    before_filter :signed_in_user, only: [:create, :update, :destroy] 
    respond_to :html, :js 

    def create 
     @user = User.find(params[:friendship][:befriended_id]) 
     @user.start_friendship!(current_user) 
     respond_with(@user, location: request.referer) 
    end 

    def destroy 
     @user = Friendship.find(params[:id]).befriended 
     current_user.end_friendship!(@user) 
     respond_with(@user, location: request.referer) 
    end 

    def update 
     @user = Friendship.find(params[:id]).befriended 
     current_user.confirm_friendship!(@user) 
     respond_with(@user, location: request.referer) 
    end 
end 

有沒有人有任何想法可能什麼錯誤,以及如何解決它?其餘的應用程序工作正常!

在此先感謝您提供的任何幫助。

UPDATE

只給一個更新 - 我安裝PostgreSQL的本地,以確保它是不是做這一點。事實並非如此。即使在生產中,它在本地託管時也能正常工作。正如我所說,我認爲問題發生在它甚至沒有進入數據庫部分。

進一步更新

的問題似乎是,它試圖渲染視圖不存在視圖渲染。我試圖擺脫位於/ app/views/friendships /中的.js.erb文件,以允許按鈕使用Ajax,但這沒有任何好處(現在我很高興無需使用Ajax) 。我可以放入一個.html.erb視圖,但我不想要一個(我只是希望它返回到用戶索引頁面)...但如果我不能提出任何其他解決方案,我可以嘗試它,只是爲了看看它是否有效。

PS我重構了早期的控制器,所以新版本在上面介紹。

+0

你可以試試'rake heroku運行assets:precompile',看看 – uday

+0

感謝您的關注!我已經嘗試過,但沒有區別 - 行爲就像它一樣。 – jimbobsweeney

回答

1

沒錯,我有它的工作,但是,至少在我看來,沒有什麼好的理由可以證明它現在可行,而且之前沒有。

爲了使它正常工作,我在生產環境中啓用了調試級日誌記錄。RB文件,通過將以下幾行:

config.log_level = :debug 
config.cache_classes = false                                     
config.action_controller.perform_caching = false 

(一定要改變config.cache_classes = true在文件的頂部)

,並投擲了一些puts語句到控制器:

puts "Current user:" + current_user.name 
puts "@user: " + @user.name 
puts "Start Friendship called. Referrer: " + request.referer 

(我只是想獲取一些信息)。

令人驚訝的是它的工作原理。如果任何人有任何想法,爲什麼這可能是,請張貼在這裏。我很高興它!

+1

我有Play應用程序,它在本地工作,但在heroku上所有非GET請求(POST,在我的情況下刪除)只是失敗返回500錯誤:( – vach

相關問題