rails_nub
rails_nub

Reputation: 67

Interesting behavior regarding Rails 'show' action on controllers

It seems like as long as a route matches 'somecontrollername#show', there is a view for it: somecontrollername/show.html, and the controller is defined without the show action, a get request to the route automatically renders the show view.

Can somebody please explain this behavior?

Upvotes: 0

Views: 32

Answers (2)

Marek Lipka
Marek Lipka

Reputation: 51151

This is how Rails work. If they have route for specific action, but this action is not implemented in appropriate controller, they try to render template named the same way as action. If they can't find this template, they throw an error.

Upvotes: 1

Matt
Matt

Reputation: 14038

You will have a resource route that automatically routes to a template show action like so:

resources :applicants # Controller for this resource can automatically serve REST requests

To remove it, in your route add except: [:show]

resources :applicants, :except => [:show] 

Upvotes: 1

Related Questions