S
S
SnowDiamond2014-12-28 02:03:33
Ruby on Rails
SnowDiamond, 2014-12-28 02:03:33

What happened to session in rails 4? Why is a hash-shaped mess displayed?

I display the query <%= session.inspect %> in the view and get quite adequate session hash data:

{"session_id"=>"22e0842b51f9e20d8a996081045b61c6", "_csrf_token"=>"ZRfXBRBEn2wKegymFjKyjSm7tS4E39JWoyuHuLs3YMU=", "hi"=>"привет"}

This is the picture in rails 3.2. But in version 4, instead I get not quite pleasant phrases:
#<ActionDispatch::Request::Session:0x007f4a746b9b38 @by=#<ActionDispatch::Session::CookieStore:0x000000033c35b8 @app=#<ActionDispatch::Flash:0x000000033c3630 @app=#<ActionDispatch::ParamsParser:0x000000033c3810 @app=#<Rack::Head:0x000000033c3838 @app=#<Rack::ConditionalGet:0x000000033c3860 @app=#<Rack::ETag:0x000000033c3978 @app=#<ActionDispatch::Routing::RouteSet:0x000000034e26b0>, @cache_control="max-age=0, private, must-revalidate", @no_cache_control="no-cache">>>, @parsers={#<Mime::Type:0x000000032e6c08 @synonyms=["text/x-json", "application/jsonrequest"], @symbol=:json, @string="application/json">=>:json}>>, @default_options={:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false}, @key="_artur_session", @cookie_only=true>, @env={"GATEWAY_INTERFACE"=>"CGI/1.1", "PATH_INFO"=>"/products", "QUERY_STRING"=>"", "REMOTE_ADDR"=>"127.0.0.1", "REMOTE_HOST"=>"127.0.0.1", "REQUEST_METHOD"=>"GET", "REQUEST_URI"=>"http://localhost:3000/products", "SCRIPT_NAME"=>"", "SERVER_NAME"=>"localhost", "SERVER_PORT"=>"3000", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/2.0.0/2014-09-19)", "HTTP_HOST"=>"localhost:3000", "HTTP_USER_AGENT"=>"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0", "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "HTTP_ACCEPT_LANGUAGE"=>"ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3", "HTTP_ACCEPT_ENCODING"=>"gzip, deflate", "HTTP_COOKIE"=>"_artur_session=U0F2aStIbHl1QnhlNVh5eUd2U2NCYUViMHVackhsMlFvNGlYWEg2cXVrWW1OeU0yWktPY0RpR0VZc0R0ZHFFSmpoTjNsT01qRHErdFF1eFBVb2Jhc21TbkQ1ZHJ2WFREMlZkWmROeVZ2QTBSbG5LM0RrVzFpQU05ejdmbXZWMEtIRCsxMXk1M3JpQ0txNjBra2dMN0lnPT0tLTVuODl3OTliSDF2bnd3N09VSDNuYVE9PQ%3D%3D--57e00255e661fec3e6ef34b8a2d337b29e183409", "HTTP_CONNECTION"=>"keep-alive", "HTTP_IF_NONE_MATCH"=>"W/\"659333aa9e3fccb8441c9e05dc0489fd\"", "HTTP_CACHE_CONTROL"=>"max-age=0", "rack.version"=>[1, 3], "rack.input"=>#<StringIO:0x007f4a7461d4b8>, "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>false, "rack.multiprocess"=>false, "rack.run_once"=>false, "rack.url_scheme"=>"http", "rack.hijack?"=>true, "rack.hijack"=>#<Proc:[email protected]/home/anhelo/.rvm/gems/ruby-2.0.0-p576/gems/rack-1.6.0/lib/rack/handler/webrick.rb:77 (lambda)>, "rack.hijack_io"=>nil, "HTTP_VERSION"=>"HTTP/1.1", "REQUEST_PATH"=>"/products", "ORIGINAL_FULLPATH"=>"/products", "ORIGINAL_SCRIPT_NAME"=>"", "action_dispatch.routes"=>#<ActionDispatch::Routing::RouteSet:0x000000034e26b0>, "action_dispatch.parameter_filter"=>[:password], "action_dispatch.redirect_filter"=>[], {"_artur_session"=>"U0F2aStIbHl1QnhlNVh5eUd2U2NCYUViMHVackhsMlFvNGlYWEg2cXVrWW1OeU0yWktPY0RpR0VZc0R0ZHFFSmpoTjNsT01qRHErdFF1eFBVb2Jhc21TbkQ1ZHJ2WFREMlZkWmROeVZ2QTBSbG5LM0RrVzFpQU05ejdmbXZWMEtIRCsxMXk1M3JpQ0txNjBra2dMN0lnPT0tLTVuODl3OTliSDF2bnd3N09VSDNuYVE9PQ==--57e00255e661fec3e6ef34b8a2d337b29e183409"}, @committed=false, @encrypted=#<ActionDispatch::Cookies::EncryptedCookieJar:0x007f4a746ec380 @parent_jar=#<ActionDispatch::Cookies::CookieJar:0x007f4a746ecdd0 ...>, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>nil, :secret_key_base=>"354d8734b492a7c936f4ef5cb405a95f00caeb5028cca8d393aa451acc60748fe82f93da901319a0cc7296b6bbf2db85e8205f121139588e1313f3044282da46", :upgrade_legacy_signed_cookies=>false, :serializer=>:json, :digest=>nil}, @encryptor=#:secret_key_base=>"354d8734b492a7c936f4ef5cb405a95f00caeb5028cca8d393aa451acc60748fe82f93da901319a0cc7296b6bbf2db85e8205f121139588e1313f3044282da46", :upgrade_legacy_signed_cookies=>false, :serializer=>:json, :digest=>nil}, @encryptor=#<ActiveSupport::MessageEncryptor:0x007f4a746ec1c8 @secret="\xFF\x7F\xF8\xAF\x12\xE2\xA9\xB9\xD9\xEA>bJ\xAE\"T\x98N\xF6\x92\x8A\x0F\xB4{\xFB\xD0\x0E\e\xE8|E\xE5\xF7\xED\xED\x15\xDC\x94\xD6\x8442ig\x7F-\xAC\x0E\xAC\x051\x1Ec\xB0\[email protected]\xDB\x92Hh\x9B\xB3Ur", @sign_secret="\x92\v>\x11\x18\xBF\xD9\xB0\x12\eP\x9B\xF8\x1A{\xACo\n\xFA\xE1\xE9\x97\xC8\xC3\xA4\e\xBD\"\x9E\xE5\xD2\x01N.\xCC\x9D\x8Cf\x14\xB8\x9B\x91D\[email protected]%\xD2\tg\aO\x82!\xB3\xB3\xDE\a\xCC3\x81)*\xA2n", @cipher="aes-256-cbc", @verifier=#<ActiveSupport::MessageVerifier:0x007f4a746ec100 @secret="\x92\v>\x11\x18\xBF\xD9\xB0\x12\eP\x9B\xF8\x1A{\xACo\n\xFA\xE1\xE9\x97\xC8\xC3\xA4\e\xBD\"\x9E\xE5\xD2\x01N.\xCC\x9D\x8Cf\x14\xB8\x9B\x91D\[email protected]%\xD2\tg\aO\x82!\xB3\xB3\xDE\a\xCC3\x81)*\xA2n", @digest="SHA1", @serializer=ActiveSupport::MessageEncryptor::NullSerializer>, @serializer=ActiveSupport::MessageEncryptor::NullSerializer>>>, "action_dispatch.request.unsigned_session_cookie"=>{"session_id"=>"205384d95faf1852d61d260a5a5e56e5", "_csrf_token"=>"xbZ461T5WCMW75bRN1gnaBpUsBV6Zuz+etPw5hhAzxE="}}, @delegate={"session_id"=>"205384d95faf1852d61d260a5a5e56e5", "_csrf_token"=>"xbZ461T5WCMW75bRN1gnaBpUsBV6Zuz+etPw5hhAzxE=", "hi"=>"привет"}, @loaded=true, @exists=true>

Part of the upper text has been cut. Tell me what is the reason, and how can I see the session hash data on version 4?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
Kirill Chernyshov, 2014-12-28
@SnowDiamond

= session.to_hash

B
Boris Penkovsky, 2015-12-30
@Able1991

Can't you see the name of the class in "not quite nice phrases"?
Working with the brain, we switch to rubidox in the description of the ActionDispatch::Request::Session class, and lo and behold, we see all the methods of the class, and among them there is the treasured to_hash www.rubydoc.info/docs/rails/4.1.7/ActionDispatch/R.. .

S
Sergey Krasnodemsky, 2014-12-28
@Prognosticator

= session[:session_id]
= session[:_csrf_token]
= session[:any_of_your_identifier]

S
SnowDiamond, 2014-12-28
@SnowDiamond

Thank you, but using the key to find the value is NOT what I need. I need a session hash with all my key - values, as in the first code example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question