Ruby on rails 3.1 自定义错误404 rails 3.1和高电压gem时出错

Ruby on rails 3.1 自定义错误404 rails 3.1和高电压gem时出错,ruby-on-rails-3.1,routes,http-status-code-404,Ruby On Rails 3.1,Routes,Http Status Code 404,嗨,伙计们,我用这个答案从高压gem上删除/page 在我的高压线路中,我有: match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get 对于rails 3.1中的维护页面404,我遵循此修复程序,使用errors\u controller.rb执行下一个代码: def routing render :file => "#{Rails.root}/public/404.html"

嗨,伙计们,我用这个答案从高压gem上删除/page

在我的高压线路中,我有:

match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
对于rails 3.1中的维护页面404,我遵循此修复程序,使用errors\u controller.rb执行下一个代码:

def routing
  render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
 end
然后,我将rails中维护页面404的下一个代码添加到routes.rb

match '*a', :to => 'errors#routing'
问题是,如果我在浏览器中输入www.mydomain.com/sdfs不工作404系统错误并显示没有这样的页面:sdfs

但是,如果我将www.mydomain.com/a_controller/action/sdfs设置为“是”,则可以很好地修复404错误页面


我认为问题出在我的路由上。rb

我通过扩展HighVoltage::PagesController并修改错误捕获来解决这个问题:

class PagesController < HighVoltage::PagesController
  rescue_from ActionView::MissingTemplate do |exception|
    render_not_found
  end
end

谢谢kevinthopson给我这个不好用的:(

我的路线中有。rb

match '/:id' => 'pages#show', :as => :static, :via => :get
我已经在页面中添加了这个\u controller.rb

class PagesController < HighVoltage::PagesController
  rescue_from ActionView::MissingTemplate do |exception|
    render_not_found
  end
end
工作正常,如果您现在投入:

本地主机:3000/dfadsfadsf

现在的问题是,如果您在导航栏中放置例如路由:

本地主机:3000/用户\u或\u静态\u页面/asdfadfadfa


不适用于我:(.

问题是修复上载行
匹配
'/:id'=>'页面#显示',:as=>:静态,:via=>:get`从routes.rb顶部
class PagesController < HighVoltage::PagesController
  rescue_from ActionView::MissingTemplate do |exception|
    render_not_found
  end
end
def render_not_found
   render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
  end