Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:04:04+00:00 2026-06-02T21:04:04+00:00

My form receives data via POST. When I do puts params I can see:

  • 0

My form receives data via POST. When I do puts params I can see:

{"id" => "123", "id2" => "456"}

now the commands:

puts params['id']    # =>  123
puts params[:id]     # =>  123

params['id'] = '999'
puts params          # => {"id" => "999", "id2" => "456"}

but when I do:

params[:id] = '888'
puts params

I get

{"id" => "999", "id2" => "456", :id => "888"}

In IRB it works fine:

params
# => {"id2"=>"2", "id"=>"1"}

params[:id]
# => nil

params['id']
# => "1"

Why can I read the value using :id, but not set the value using that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:04:07+00:00Added an answer on June 2, 2026 at 9:04 pm

    Hashes in Ruby allow arbitrary objects to be used as keys. As strings (e.g. "id") and symbols (e.g. :id) are separate types of objects, a hash may have as a key both a string and symbol with the same visual contents without conflict:

    irb(main):001:0> { :a=>1, "a"=>2 }
    #=> {:a=>1, "a"=>2}
    

    This is distinctly different from JavaScript, where the keys for objects are always strings.

    Because web parameters (whether via GET or POST) are always strings, Sinatra has a ‘convenience’ that allows you to ask for a parameter using a symbol and it will convert it to a string before looking for the associated value. It does this by using a custom default_proc that calls to_s when looking for a value that does not exist.

    Here’s the current implementation:

    def indifferent_hash
      Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
    end
    

    However, it does not provide a custom implementation for the []=(key, val) method, and thus you can set a symbol instead of the string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My server receives multipart form data from a mobile app. The result of printing
I have a form, in which I need to send data selected via AJAX
I have been trying to retrieve data via AJAX. I can't seem to be
In ASP.net MVC: How should/Can I pass Form data (From the View) to the
I have an application that receives data in binary form through Bluetooth. I read
This is a newbie question... I receive data from the user via a form,
So I have a form that can get data from a database by its
I am using ASP.NET MVC 1.0. I have an ActionResult which receives a form
A form I don't have any control over is POSTing data to my PHP
A form, I use AJAX to transfer the data. The AJAX is triggered by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.