Note that there are some explanatory texts on larger screens.

plurals
  1. POSession not saving variable
    primarykey
    data
    text
    <p>I am using Ruby on Rails and for some reason when I try to store a hash in my session it doesn't transfer across pages, however the test variable does. The code is as follows:</p> <pre><code>class HomeController &lt; ApplicationController require 'read_file' def index session[:test] = 1 end def uploadDictionary #post = ReadFile.read(params['dictionary']) file = params['dictionary'] wordHash = Hash.new(0) file.read.each_line do |line| wordHash[line.downcase] = line.downcase #session[:hmm] = line #puts session[:hmm] end #wordHash.each { |key, value| puts key + ' = ' + value + "\n" } session[:storedDictionary] = wordHash #session[:storedDictionary].each { |key, value| puts key + ' = ' + value + "\n" } puts session[:test] redirect_to :action =&gt; "index" end def checkWord session[:storedDictionary].each { |key, value| puts key + ' = ' + value + "\n" } #puts session[:storedDictionary].key(params[:submittedWord].downcase) puts session[:test] render :text =&gt; "woot" end end </code></pre> <p>The issue is session[:storedDictionary] doesn't maintain itself across uploadDictionary and checkWord, I am hoping someone could give me some advice. Thanks. Update to show my view code:</p> <pre><code>&lt;h1&gt;Home#index&lt;/h1&gt; &lt;p&gt;Find me in app/views/home/index.html.erb&lt;/p&gt; &lt;%= form_tag({:action =&gt; :uploadDictionary}, :multipart =&gt; true) do %&gt; &lt;%= file_field_tag 'dictionary' %&gt; &lt;%= submit_tag "Upload" %&gt; &lt;% end %&gt; &lt;br&gt; &lt;br&gt; &lt;%= form_tag("/checkWord", :method =&gt; 'get') do %&gt; &lt;%= text_field_tag 'submittedWord' %&gt; &lt;%= submit_tag "checkWord" %&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload