Custom Rails Error Pages
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the rails 3 custom error pages company Business Learn more about hiring developers or posting ads with us Stack Overflow rails 500 error page Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 rails rescue from million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Rails 4: How do I create a custom 404 page that uses the asset pipeline? up vote 14 down vote rails 4 custom error pages favorite 5 There are many solutions for creating customized error handling pages, but almost none for Rails 4: Basic Rails 404 Error Page Dynamic error pages in Rails The standard answer of encouraging people to modify 404.html in /public doesn't work for me because I want to use the CSS theme that resides in the asset pipeline. Is there a way that html files can access those styles defined in the asset pipeline?
Rails Dynamic Error Pages
If not, is there a way to create a custom error handler that has access to the pipeline? ruby-on-rails ruby-on-rails-4 error-handling asset-pipeline share|improve this question asked Jun 16 '14 at 2:01 Avery 2,28372642 I think on your second reference have what do you want. but almost none for Rails 4 , Are you sure the second reference not work on rails 4? What you have done already? –rails_id Jun 16 '14 at 2:35 add a comment| 3 Answers 3 active oldest votes up vote 23 down vote For Rails 4.1 I like this answer, add an asset type better; however I have not tried it. On Rails 4.0.8, these three references helped me: Dynamic error pages is the second reference in the question. This worked just fine for me. Custom error pages may have cribbed from the first reference, or the other way around, but goes the extra mile by adding some information about testing with Capybara. I did not do the Capybara testing because I didn't want to change the test configuration; however, RSpec-Rails Request Specs clued me in to test these requests independently and see that they complete and return the correct content. What follows is a nutshell description of what is taught by the three references: Add the following setting to config/enviro
Support Search GitHub This repository Watch 35 Star 164 Fork 11 mirego/gaffe Code Issues 4 Pull requests 0 Projects 0 Pulse Graphs đź’Ą Gaffe handles
Custom Rails Validation
Rails error pages in a clean, simple way. http://open.mirego.com 115 commits 2 custom rails logger branches 10 releases Fetching contributors BSD-3-Clause Ruby 79.1% HTML 11.0% CSS 9.3% Groff 0.6% Ruby HTML CSS Groff Clone custom rails helper or download Clone with HTTPS Use Git or checkout with SVN using the web URL. Open in Desktop Download ZIP Find file Branch: master Switch branches/tags Branches Tags feature/coveralls master Nothing http://stackoverflow.com/questions/24235805/rails-4-how-do-i-create-a-custom-404-page-that-uses-the-asset-pipeline to show v1.2.0 v1.1.0 v1.0.2 v1.0.1 v1.0 v0.2.1 v0.2 v0.1.2 v0.1.1 v0.1 Nothing to show New pull request Fetching latest commit… Cannot retrieve the latest commit at this time. Permalink Failed to load latest commit information. app Display errors also in development. Downcase color code. Apr 14, 2014 gemfiles Remove Rails 3 support Feb 25, 2016 lib Bump version to 1.2 Sep 5, https://github.com/mirego/gaffe 2016 spec Merge pull request #32 from uzzer/feature/support-custom-domain-in-co… Apr 25, 2016 .gitignore Initial commit Jul 12, 2013 .phare.yml Add .phare.yml Jun 3, 2014 .rspec Add basic tests Jul 15, 2013 .rubocop.yml Add phare to Travis script commands May 7, 2014 .travis.yml Remove Rails 3 support Feb 25, 2016 Gemfile Remove Rails 3 support Feb 25, 2016 LICENSE.md Update copyright year Feb 25, 2016 README.md Support pattern matching by absolute URL Apr 22, 2016 Rakefile Add basic tests Jul 15, 2013 gaffe.gemspec Remove Rails 3 support Feb 25, 2016 README.md Gaffe makes having customized error pages in Rails applications an easy thing. It takes advantage of a feature present in Rails 3.2 (and 4.0+, obviously) called exceptions_app. It comes with default error pages but makes it very easy to override them (which you should do). The default error pages look like this: Installation Add this line to your application’s Gemfile: gem 'gaffe' Usage The easiest way to use Gaffe is with an initializer: # config/initializers/gaffe.rb Gaffe.enable! Custom controller However, if you want to use your own controller: # config/initializers/gaffe.rb Gaffe.configure do |config| config.errors_controller = 'ErrorsController' end Gaffe.ena
you just use the router as the exceptions app, but then you have to handle those other errors as well. It's very much based error page on this Gist by Turadg Aleahmad, but with some cleanup and fixes. Code changes Remove the default public/404.html to avoid any collisions. Modify these files like so: config/application.rb1 2 3 4 5 6 7 8 custom error pages 9 10 # … module NameOfMyApp class Application < Rails::Application # … require Rails.root.join("lib/custom_public_exceptions") config.exceptions_app = CustomPublicExceptions.new(Rails.public_path) end end config/routes.rb1 2 3 4 5 Rails.application.routes.draw do match "/404" => "errors#error404", via: [