Why Alloy actions translate to <action>Method for non-GET requests

11 views
Skip to first unread message

Vance Lucas

unread,
Mar 24, 2011, 12:22:16 PM3/24/11
to Alloy
Just came across this post on the default behavior of Ruby on Rails,
and my own experiences with Rails that led me to the same beliefs as
the conclusion of this post. This is why Alloy uses a different
prepended name for controller methods that are accessed with a GET
request vs. POST, PUT, DELETE, etc. Simply put, this is never a
problem when using Alloy, even when using a default "/controller/id/
action" type route.

The Rails default route is not your friend:
http://www.nolanevans.com/2011/03/rails-default-route-is-not-your-friend.html

Chris Boden

unread,
Mar 26, 2011, 6:46:58 PM3/26/11
to Alloy
Hi Vance,

I noticed you talked about this in your slideshow, but I seem to be
missing something...

With a route:
$router->route('test', '/<:identity>(.<:format>)')-
>defaults(Array('module' => 'Test', 'action' => 'index', 'format' =>
'html'));

And a Controller:
class Controller extends App\Module\ControllerAbstract {
public function indexAction(Alloy\Request $request) {
return 'Action: ' . $_SERVER['REQUEST_METHOD'];

public function indexMethod(Alloy\Request $request) {
return 'Method: ' . $_SERVER['REQUEST_METHOD'];


I get results: "Action: GET" and "Action: POST" respectively. From
what I understand, when a request is made with POST, my indexMethod()
function should be called.

Vance Lucas

unread,
Mar 28, 2011, 1:13:54 PM3/28/11
to allo...@googlegroups.com
The dispatcher does append Action or Method like this for any named method, but your limitation here is the Router. This is a bit of a limitation because of Alloy's REST preference (a Controller is a REST resource), and as a result the controller will only have one method each that can receive a POST, PUT, and DELETE request.

Currently, you would have to specify an action to route to for POST requests:

$router->route('test', '/<:identity>(.<:format>)')
    ->defaults(Array('module' => 'Test', 'action' => 'index', 'format' => 'html'))
    ->post(array('action' => 'index'));

--
Vance Lucas
http://vancelucas.com
Reply all
Reply to author
Forward
0 new messages