Action name like "sort" is not possible?

Hi all

Just wondered that I can’t create an action called sort in my
controller… I guess this is due to the fact that there’s already an
“innate” method called “sort” in the controller? Could that be?
Is there a list of “names-not-to-use-for-actions” or something like
that? Or is there a way to use these names anyway?

Thanks,
Josh

sort is a ruby method that can be performed, so using it will cause
confusion for the framework:
Did you mean “run the sort method, or sort this object?”.

There are a whole heap of these reversed words (some are even hidden).
I did see a list somewhere, but cannot find it.

To get around the problem rename the action and create a route to it:
map.connect ‘/ControllerName/search’, :controller => ‘ControllerName’,
:action =>‘MyNewName’

Are there better ways?

On 12/12/06, Joshua M. [email protected] wrote:

Hi all

Just wondered that I can’t create an action called sort in my
controller… I guess this is due to the fact that there’s already an
“innate” method called “sort” in the controller? Could that be?

Not that I can see in 1.1.6 at least. Perhaps your #sort is not
public? What error are you getting?

Is there a list of “names-not-to-use-for-actions” or something like
that? Or is there a way to use these names anyway?

A good rule of thumb is to not use method names that already exist.
To find them, try this in script/console:

puts ApplicationController.instance_methods.sort

You should probably avoid clobbering private methods too:

puts ApplicationController.private_instance_methods.sort

…although private methods in Object and Kernel are probably safe to
override if you must:

a, k, o = [ApplicationController, Kernel, Object].map{|m|
m.private_instance_methods}
puts (a - k - o).sort

Thank you guys.

It’s kind of a pitty that Rails does not use some sort of naming
convention for actions, I saw frameworks that do, e.g.

def action_index

end

def action_sort

end

etc.

Names like “sort” are precious for a good looking and indexed website,
and to create a route for every little action is kind of making tired…