I just started to learn Rails and I cannot understand that:
In my Post controller I do not have method show (not described), but I put in my controller that:
def method_missing(name, *args)
redirect_to posts_path
end
I think that if controller couldn’t find action show – it would call method_missing and after that redirect to index method, but Rails tries to render view show.html.erb.
Why is method missing not catching? How can I use method_missing?
Rails does not require action to be present in controller if corresponding template exists. It just assumes empty action and renders template, that is why your
method_missingisn’t invoked.If you don’t need
showaction anyway – just removeshow.html.erbandmethod_missingwill work as expected.