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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6a657bbaaa704aa1fc7dfa6d680c06fc?d=identicon&s=25 bluengreen (Guest)
on 2007-07-30 18: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 ])
 end

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

end


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?

Thansk,
Phill Novess
Ca35abdcc0ebbaada3c935c2746ed5ea?d=identicon&s=25 Mantat (Guest)
on 2007-07-30 21: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.