Skip to content

Instantly share code, notes, and snippets.

@SandNerd
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save SandNerd/4cc2d6d4027c98908dd0 to your computer and use it in GitHub Desktop.

Select an option

Save SandNerd/4cc2d6d4027c98908dd0 to your computer and use it in GitHub Desktop.

Params

HTTP/HTML Params

  • Series of key-value pairs (e.g. key: 'value'). Both are strings
  • Come from the user's browser when they request the page
  • Encoded in the url
Example

For an HTTP GET request, if a user's browser requested

http://www.bs.com/?foo=1&boo=octopus

Then:

  • params[:foo] would be "1"
  • params[:boo] would be "octopus"

Rails & Params

Rails has a special syntax for making params into a hash with hashes inside

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"
  • params[:vote][:user_id] would be "2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment