Access Ruby hash variables

后端 未结 3 722
南旧
南旧 2021-02-01 19:58

I am pretty new to ruby and sinatra but basically I have this route:

put \'/user_list/:user_id\' do
    puts request.params[\"model\"]
end

and

3条回答
  •  孤街浪徒
    2021-02-01 20:11

    The standard Hash treats strings and symbols differently, and I'd be willing to bet that's what's happening in this case.

    Use request.params["model"]["password"] to get the password.

    The exception to that is when working with a HashWithIndifferentAccess which is part of ActiveSupport. For hashes of that type, either strings or symbols can be used to access the same elements.

提交回复
热议问题