I've been looking on how to set this up to render a page when a template is not found. Can anyone help me with this? Thank you all.
So when someone requests a non-existent page that hits the high voltage controller, you want to render something other than the 404.html page?
When it doesn't find the page, it renders a message like: Cannot find page: /page/foo
I want it to render my custom 404 page, but I don't get a clue about how to do it.
If you look here, you can see what it's doing - https://github.com/thoughtbot/high_voltage/blob/master/app/controllers/high_voltage/pages_controller.rb#L5-11
If you try to handle an ActionController::RoutingError in your custom 404, will that work?
So, if i want to get 404.html served by high_voltage, I need a custom PagesController?
I would like to remove public/404.html and add /app/pages/404.hml, but I underestand that doesn't work like this.
Am I right?
Rendering a dynamic 404 page in rails is not necessarily related to high_voltage, if that's what you want. Check out the rescue_from method - http://api.rubyonrails.org/classes/ActiveSupport/Rescuable/ClassMethods.html#method-i-rescue_from - that might help.
If you ARE trying to add 404 customization to high_voltage, can you be more specific about what you want to do?
Since high_voltage is an engine there seems to be a problem using the normal rescue_frommethod. Therefor it would be nice to at least have the option to have a default page which would be rendered when no page was matched.
this gem seems to fix the problem https://github.com/vidibus/vidibus-routing_error
@mjankowski, what i was trying to do was use high_voltage to render a dynamic 404.
As you say, this can be achieved without high_voltage, this is what I have in application_controller.rb:
rescue_from Exception, :with => :render_500
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
rescue_from ActionController::RoutingError, :with => :render_404
rescue_from ActionController::UnknownController, :with => :render_404
rescue_from ActionController::UnknownAction, :with => :render_404
def render_500 exception
render :template => "/pages/500.html.erb", :status => 500, :layout => 'static'
def render_404 exception
render :template => "/pages/404.html.erb", :status => 404, :layout => 'static'
Sorry to ressurect such an old issue, but I've tried to implement this the way @dormi suggests and HV doesn't seem to catch the "rescue_from ActionController::RoutingError, :with => :render_404" in my application controller.
I get the vanilla error page with page not found.
I've also tried the suggestion from @Godisemo and the vidibus page about using the config.exceptions_app = self.routes trick - but that doesn't work at all.
I'm on Rails 3.2.11 and HV 1.2.2...
It is depend on particular use case, but in case someone looking to simply handle invalid pages:
class PagesController < ApplicationController
render('pages/404-error', :status => 404)
Please see "Override" scection for more details about PagesController:
invalid_page is the method from HighVoltage::StaticPage module, which, by default, raises ActionController::RoutingError https://github.com/thoughtbot/high_voltage/blob/54217603f6745a1feecff6761bc600dc07631ba4/app/controllers/concerns/high_voltage/static_page.rb#L22-L24