404 Custom Action in Rails

By default, Rails will display 404.html, then it considers the 404 error to be appropriate. However, I want to do this on a special page. Please suggest the right way to do this.

+3
source share
3 answers

You can use render_404 beheading monkeys.

Or you can set a default route at the bottom of the routes file, which jumps to an action that returns a 404 status code.

Ideally, if you don't need any custom code in your 404, you can simply edit the static 404.html file, which is easiest.

+3
source

.

, 404.html. .

, :

config/routes.rb:

match '*not_found', to: 'errors#error_404' unless Rails.application.config.consider_all_requests_local

unless, 404 .

:

rails generate controller errors error_404

views/errors/error_404.html.erb .

Rails 3.1 3.2.2.

+4

Depending on what you need, our gemstone may help: http://github.com/hedgeyedev/snow

0
source

Source: https://habr.com/ru/post/1772990/


All Articles