Tag: http status code 404

Rails 4自定义404导致Heroku上的postgresql连接失败

我在生产中使用自定义域部署了一个Rails 4应用程序。 我也有一个升级版本。 该应用程序使用舒适的墨西哥沙发。 出现以下问题:应用程序将达到所有请求返回500错误的状态。 日志显示: [jesse@Athens expat]$ heroku logs ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)): [jesse@Athens expat]$ heroku pg:info Connections: 5 [jesse@Athens expat]$ heroku pg:ps pid | state | source | running_for | waiting | query —–+——-+——–+————-+———+——- (0 rows) [jesse@Athens expat]$ heroku pg:killall pg_terminate_backend ———————- t t […]

如何正确呈现自定义404和500页?

是否有办法告诉Rails呈现您的自定义错误页面(例如,您在ErrorsController编写的错误页面)? 我搜索了很多主题,看起来有点工作的是添加到你的ApplicationController东西 if Rails.env.production? rescue_from Exception, :with => :render_error rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found rescue_from ActionController::UnknownController, :with => :render_not_found rescue_from ActionController::UnknownAction, :with => :render_not_found end 然后你按照你想要的方式编写你的方法render_error和render_not_found 。 在我看来,这似乎是一个非常不优雅的解决方案。 此外,这很糟糕,因为您必须确切知道可能发生的所有错误是什么。 这是一个临时解决方案。 而且,实际上没有简单的方法来拯救ActionController::RoutingError 。 我看到一种方法是添加类似的东西 get “*not_found”, :to => “errors#not_found” 到你的routes.rb 。 但是如果你想手动提升ActionController::RoutingError呢? 例如,如果非管理员的人试图通过猜测URL来“管理”控制器。 在那些情况下,我更喜欢提高404而不是某种类型的“未经授权的访问”错误,因为这实际上会告诉该人他猜到了URL。 如果你手动提高它,它将尝试渲染500页,我想要一个404。 那么有没有办法告诉Rails:“在所有情况下,你通常会渲染一个404.html或500.html ,渲染我的自定义404和500页”? (当然,我从public文件夹中删除了404.html和500.html页面。)

Zurb Foundation 5,找不到modernizr

在生产模式下使用Foundation 5.0.2.0时,我得到了这个。 在Rails,Unicorn,NginX和Ubuntu上。 “NetworkError: 404 Not Found – http://mydomain.com/javascripts/vendor/modernizr.js”

在Rails 3中捕获自定义404的未知操作

我想在Rails 3中捕获未知的操作错误,该错误显示开发时的“未知操作”错误以及生产中的404.html。 我尝试将这个rescue_from处理程序放在我的ApplicationController上(以及实际的控制器,以防万一),但我仍然看到了丑陋的错误。 我在404上有自定义的东西,它不能是普通的.html文件。 我的路线: match ‘/user/:id/:action’, controller: ‘users’ 我正在访问的URL: /user/elado/xxx rescue_from代码: rescue_from AbstractController::ActionNotFound, :with => :action_not_found def action_not_found render text: “action_not_found” end 浏览器中的错误: Unknown action The action ‘xxx’ could not be found for UsersController 在控制台中: Started GET “/user/elado/xxx” for 127.0.0.1 at 2011-09-07 19:16:27 -0700 AbstractController::ActionNotFound (The action ‘xxx’ could not be found for UsersController): […]

基本Rails 404错误页面

我一直在寻找一个简单的答案,这是一个非常漫长的时间,似乎这一点非常明显和简单,因为没有人有一个简单的,白痴certificate教程。 无论如何,我想做的就是有一个单独的404.html静态页面,无论何时抛出任何错误都会加载。 理想情况下,这应该只在生产和分期中发生。 我觉得这应该是最简单的事情……但我无法弄明白。 任何帮助深表感谢。

用自定义图像替换破碎的外部图像

我正在遍历在外部站点托管的一系列URL图像字符串。 它看起来像这样: def get_image_urls image_url_array.each do |image_url| puts image_tag image_url end end 这将返回外部站点上托管的图像的URL。 问题是,其中一些图像可能会被破坏(404)。 例如: get_image_urls # These would return image_tags, but for brevity… => “http://sofzh.miximages.com/ruby-on-rails/1.jpg” “http://sofzh.miximages.com/ruby-on-rails/2.jpg” “http://sofzh.miximages.com/ruby-on-rails/3.jpg” # <– (Broken: 404) "http://sofzh.miximages.com/ruby-on-rails/4.jpg" "http://sofzh.miximages.com/ruby-on-rails/5.jpg" # <– (Broken: 404) 我要做的是将损坏图像的URL字符串替换为我自己网站上托管的“缺失”图像。 所以使用上面的例子,3.jpg和5.jpg被打破了,我想要返回这样的东西: get_image_urls # These would return image_tags, but for brevity… => “http://sofzh.miximages.com/ruby-on-rails/1.jpg” “http://sofzh.miximages.com/ruby-on-rails/2.jpg” “http://mysite.com/images/missing.png” “http://sofzh.miximages.com/ruby-on-rails/4.jpg” “http://mysite.com/images/missing.png” […]

如何在Nokogiri中处理404未找到的错误

我正在使用Nokogiri来抓取网页。 几个url需要被猜到,并且当它们不存在时返回404未找到的错误。 有没有办法捕获此exception? http://yoursite/page/38475 #=> page number 38475 doesn’t exist 我尝试了以下哪些不起作用。 url = “http://yoursite/page/38475” doc = Nokogiri::HTML(open(url)) do begin rescue Exception => e puts “Try again later” end end