Reputation: 23
I want to loop through all the variables stored in the session. I checked and it appears that sessions are stored as a hash: request.session.kind_of?(Hash) - returns true
I wasn't sure why the following code didn't work: request.session.each {|key, value| puts keys + " --> " + value
I am trying to output all session variables as part of a debug view.
Upvotes: 2
Views: 2129
Reputation: 6712
request.session.to_hash.each{|key, value| puts "#{key.to_s} --> #{value.to_s}"}
Upvotes: 1
Reputation: 12749
<%= debug session %>
might be easier.
Use it like this:
<% if ENV['RAILS_ENV'] == 'development' %>
<%= javascript_include_tag 'prototype' %>
<%= debug session %>
<%= debug params %>
<% end %>
Upvotes: 1
Reputation: 11596
Instead of:
request.session.each {|key, value| puts keys + " --> " + value
Use:
request.session.each {|key, value| puts key.to_s + " --> " + value.to_s }
Upvotes: 4