The params come from the user's browser when they request the page. For an HTTP GET request, which is the most common, the params are encoded in the url. For example, if a user's browser requested
http://www.example.com/?foo=1&boo=octopus
then params[:foo]
would be "1" and params[:boo]
would be "octopus".
In HTTP/HTML, the params are really just a series of key-value pairs where the key and the value are strings, but Ruby on Rails has a special syntax for making the params be a hash with hashes inside. For example, if the user's browser requested
http://www.example.com/?vote[item_id]=1&vote[user_id]=2
then params[:vote]
would be a hash, params[:vote][:item_id]
would be "1" and params[:vote][:user_id]
would be "2".
The Ruby on Rails params are the equivalent of the $_REQUEST array in PHP.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…