Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 在Rails上发布/删除请求,查找Heroku上不应显示的视图';不可能。在本地完美工作_Ruby On Rails 3_Heroku_Ruby On Rails 3.2_Railstutorial.org - Fatal编程技术网

Ruby on rails 3 在Rails上发布/删除请求,查找Heroku上不应显示的视图';不可能。在本地完美工作

Ruby on rails 3 在Rails上发布/删除请求,查找Heroku上不应显示的视图';不可能。在本地完美工作,ruby-on-rails-3,heroku,ruby-on-rails-3.2,railstutorial.org,Ruby On Rails 3,Heroku,Ruby On Rails 3.2,Railstutorial.org,我在Rails应用程序的用户索引页面上有一个用户列表,我的想法是,登录的用户可以通过单击其姓名旁边的“开始友谊”按钮与其他用户建立友谊。这会将一条记录添加到友谊表中 在本地托管时,该进程可以完美地工作。这使用SQLite(尽管我认为这不是数据库问题),日志如下所示: Started POST "/friendships" for 127.0.0.1 at 2013-01-25 12:48:16 +0000 Processing by FriendshipsController#create as

我在Rails应用程序的用户索引页面上有一个用户列表,我的想法是,登录的用户可以通过单击其姓名旁边的“开始友谊”按钮与其他用户建立友谊。这会将一条记录添加到友谊表中

在本地托管时,该进程可以完美地工作。这使用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)
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
然而,当我在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
它甚至似乎还没有达到数据库的高度。我已经尝试将coffee-rails gem从资产转移到Gemfile的主体(如前所述),根本没有haml gem(如前所述),我的rake-db东西似乎是正确的(如前所述)

友谊控制器如下所示:

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)
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
类友谊控制器
有人知道可能出现什么问题以及如何解决吗?应用程序的其余部分工作正常

提前感谢您提供的任何帮助

更新

只是为了提供一个更新——我在本地安装了PostgreSQL,以确保它与此无关。事实并非如此。即使在生产环境中,在本地托管时也能正常工作。正如我所说的,我认为问题发生在它甚至没有到达数据库部分的事实上

进一步更新

问题似乎是它试图渲染一个没有要渲染的视图的视图。我尝试过去掉/app/views/friendships/中的.js.erb文件,以允许按钮使用Ajax,但这没有任何好处(我很高兴现在没有Ajax)。我可以放在一个.html.erb视图中,但我不想要一个(我只想让它返回到用户索引页)…尽管如果我不能想出任何其他解决方案,我可能会尝试一下,看看它是否有效


PS我从早期重构了控制器,因此新版本在上面展示。

是的,我已经让它工作了,但是,至少在我看来,没有充分的理由认为它现在工作,以前没有

为了使其正常工作,我在production.rb文件中启用了调试级日志记录,方法是在其中放入以下行:

config.log_level = :debug
config.cache_classes = false                                                                                                                                                 
config.action_controller.perform_caching = false
(确保更改文件顶部的
config.cache\u classes=true

并将一些
puts
语句扔到控制器中:

puts "Current user:" + current_user.name
puts "@user: " + @user.name
puts "Start Friendship called. Referrer: " + request.referer
(我只是想了解一些情况)


令人惊讶的是,它起作用了。如果有人知道为什么会这样,请把它贴在这里。我很高兴它能做到

您可以尝试执行
rake heroku run assets:precompile
并查看感谢您的关注!我已经试过了,但没有什么区别——行为还是原来的样子。我的Play应用程序也有同样的问题,它在本地工作,但在heroku上,所有非GET请求(在我的情况下是POST、DELETE)都无法返回500个错误:(