Only when I create a 404 error page in Rails, the image posted by refile disappears. If you comment out the code on the error page, the image will be displayed.
The code for the 404 error page is below.
application_controller.rb
unless Rails.env.development?
rescue_from Exception, with: :render_500
rescue_from ActiveRecord::RecordNotFound, with: :render_404
rescue_from ActionController::RoutingError, with: :render_404
end
#Create an error directory with views and 404 there.html.erb/505.html.Create erb
def render_404
render 'error/404', status: :not_found
end
def render_500
render 'error/500', status: :internal_server_error
end
config/routes.rb
Rails.application.routes.draw do
#It will be evaluated in order from the top, so write it at the bottom
get '*path', to: 'application#render_404'
end
If you check rails routes in the terminal,
GET /*path(.:format)
refile_app /attachments
It was in the order of.
Since routes are evaluated from above, get'* in
config / routes.rbis evaluated before
/ attachments, which is the URL of the refile with nothing set in
config / routes.rb, is evaluated. path', to:'application # render_404'
has been evaluated.
It's okay to evaluate refile_app / attachments
beforeGET / * path (.: Format)
.
First, add the following to ʻinitializers / refile.rb. If
refile.rb` does not exist, create a new one.
config/initializers/refile.rb
Refile.automount = false
config/routes.rb
Rails.application.routes.draw do
mount Refile.app, at: Refile.mount_point, as: :refile_app #add to
get '*path', to: 'application#render_404' #Write at the bottom
end
If you check rails routes in the terminal,
refile_app /attachments
GET /*path(.:format)
I think it is in the order of.
I think that / attachments
will be evaluated first and the image will be displayed.
https://github.com/refile/refile#mounting As I wrote in, I had to turn off the automatic mounting of refile and set the route myself.