parameters wrapper docs :
Wraps a parameter hash in a nested hash. This will allow clients to send POST requests without specifying any root elements.
Helps to have parameter hashes wrapped. The Action Controller review provides the following:
Rails collects all parameters sent along with the request in the params hash, regardless of whether they are sent as part of the request line or message body. [...] The query_parameters hash contains parameters that were sent as part of the query string, and the request_parameters hash contains parameters sent as part of the message body. The path_parameters hash contains parameters that were recognized by routing as part of the path leading to this particular controller and action.
Fun happens when you use RESTful resources and routes. Say you have a model A that has_many Bs; B has a foreign key a_id .
You are POST /as/1/bs with an empty payload (because B has no other fields). Assuming a_id is attr_accessible , we can assume that a_id will be wrapped in object b . Instead, you will see:
Processing by BsController#create as HTML Parameters: {"b"=>{}, "a_id" => "1"}
There is no such luck. It turns out that ParamsWrapper uses request_parameters , not params , so not including a_id in the POST payload means t wrap it up. This is rather confusing because you still think that it is included in params , due to URI hangs, and wonder why it was excluded from all things.
Is there any good reason to use request_parameters rather than params here?
I can understand that from the “REST philosophy” point of view, this is a_id if you assume that the payload contains the whole object, but it essentially means that the a_id in the URI is completely ignored, which seems a pity.
tl; dr: ParamsWrapper uses request_parameters as the source of the parameter, so URI-globbed variables are skipped. Is this a Rails bug? Pure REST advocates may say no, but pragmatism suggests yes.