title: Storing user data in a session and use it later in a form (Rails)?
body: <p>I have an <code>omniauth_create</code> action in my <strong>sessions</strong> controller. It redirects the user to a view called <strong>enter_email.html.erb</strong> and passes some <code>params</code> to the redirect (fetched from <a href="https://github.com/intridea/omniauth/wiki" rel="nofollow">omniauth</a>):</p>
  
  <pre><code>  def omniauth_create
      auth = request.env["omniauth.auth"]
      user = User.from_omniauth(env["omniauth.auth"])
      .
      .
      .
      else
        redirect_to(enter_email_path(oprovider: user.provider,
                                     ouid: user.uid,
                                     oname: user.name,
                                     opassword: user.password,
                                     opassword_confirmation: user.password))
      end
    end
  </code></pre>
  
  <p>Where they are used in hidden fields (basically a registration form):</p>
  
  <pre><code>&lt;%= form_for(@user) do |f| %&gt;
        &lt;%= render 'shared/error_messages', object: f.object %&gt;
  
        &lt;%= f.label :email %&gt;
        &lt;%= f.text_field :email %&gt;
  
        &lt;%= f.hidden_field :provider, value: params[:oprovider] %&gt;
        &lt;%= f.hidden_field :provider, value: params[:oprovider] %&gt;
        &lt;%= f.hidden_field :uid, value: params[:ouid] %&gt;
        &lt;%= f.hidden_field :name, value: params[:oname] %&gt;
        &lt;%= f.hidden_field :password , value: params[:opassword] %&gt;
        &lt;%= f.hidden_field :password_confirmation, value: params[:opassword_confirmation] %&gt;
  
        &lt;% # To know to which form to redirect in case of validation error %&gt;
        &lt;%= hidden_field_tag 'form_name', 'enter_email' %&gt;
  
        &lt;%= f.submit "Create my account", class: "btn btn-large btn-primary" %&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <p>Now the problem is that when there is validation error (e.g. the email had been already taken). The view renders <code>enter_email</code> and the <code>params</code> are wiped out from the hidden fields (from value).</p>
  
  <p>So I was thinking of storing the data in a <strong>session</strong> instead of passing them with <code>redirect_to</code> I have never used sessions this way, so I'm a bit lost (I'm not even sure if I still need the hidden fields if I store data in a session?)</p>
  
  <p>Can anyone give me a hint or an example?</p>