Rails and params hash (from Google Cache)
Originally posted January 7, 2010
I’ve been working with Rails long enough that I should start to remember some things, but that is not always the case. I’d always been getting confused about the params[:id] line that I would see all over the place. I’m hoping that by writing this down, I’ll remember what it means.
The params object is simply a hash that holds all of the parameters passed in the browser request. Since most routes are of the form :controller/:action/:id, a url like this:
http://localhost:3000/users/list/7
params[:controller] = users
params[:action] = list
params[:id] = 7
The first two aren’t used that much, but params[:id] is very, very common.