Forum: Ruby on Rails Is this a bug or expected behavior?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
bluengreen (Guest)
on 2007-07-30 20:54
(Received via mailing list)
Just wondering if anybody has had this "problem" or feature with Rails
apps. I noticed that if I drop a .rhtml file in the views folder for a
controller I can render that template by action name even though I
have not defined the action in my controller.

For example. I created a products controller. I added a index method
in the controller. There is a coordinating views directory - app/views/
products. This directory has a index.rhtml file.  I added a edit.rhtml
and _form.rhtml that was created using a generated scaffold.

My controller is bare bones:

class ProductsController < ApplicationController

 def index
   @products = Product.find_products_for_sale
   @tree = Category.find(:all, :include => [ :children ])

 def show
   @product = Product.find(params[:id])


Ok. So if I go to localhost:3003/products/edit/. I get the edit page
and the form. The form will not process but it still displays. To me,
this seems like incorrect behavior since I have not defined the action
in my controller. It also seems to go against the idea of my
controller - controlling.  I dunno. Anybody else experience this? Is
this suppose to be like this?

Phill Novess
Mantat (Guest)
on 2007-07-30 23:33
(Received via mailing list)
by default, the route.rb will take any :controller/:action call you
send to it and then check if it can be processed. If you delete that
route and only use named routes (as you should in preparation for RoR
2.0, only predefined routes/actions will be accessible.
This topic is locked and can not be replied to.