0

In ruby there is a concept called method_missing, I am trying to implement the same in rails.

class GalleryController < ApplicationController
  def gallery_home
  end
  def method_missing(m, *args)
    render plain: "There is no method #{m}"
  end
end

But still the default rails error page appears. Any pointers please where I am going wrong

EDIT: I am trying to display an nice custom error message, when the route does not match.
I don't want to show the user The page you were looking for does not exist.

gates
  • 4,465
  • 7
  • 32
  • 60
  • Please, show the error message. It seems like this error will be caused by missing route/view. – Sergii K Jun 17 '16 at 06:04
  • I think you are looking for this [Link](http://stackoverflow.com/questions/19653761/how-redirect-to-404-page-in-routes-rb) – Pravesh Khatri Jun 17 '16 at 06:12
  • I can't help you if I don't know type of error. 7 lines of code can't describe your application, don't you think? – Sergii K Jun 17 '16 at 06:13
  • Take a look at this answer http://stackoverflow.com/a/25842118/4493564 – Petr Gazarov Jun 17 '16 at 06:59
  • @gates could you provide more information? Specifically, I'm curious how you route to the controller. Do you determine the action dynamically? If no, why do you want to handle controller actions that won't be called by the router? – Greg Navis Jun 17 '16 at 10:17
  • Do you need to do this for all undefined routes or under specific controller? If it is for all routes, add a custom path at the end of your routes file which will render all unmatched requests to that action. Something like: - http://stackoverflow.com/questions/8680439/how-can-i-create-a-rails-3-route-that-will-match-all-requests-and-direct-to-one – noman tayyab Jun 17 '16 at 16:09

0 Answers0