I am trying to find a RESTful way to make my signup confirmation process work smoothly. I am using Rails 4 and Devise 3.0. The process flow works as so:
User sign up -> confirmation email sent -> user clicks confirm email link -> user is directed to the leads controller where it generates a lead (blank page to user for about 2 seconds) -> then the user is redirected to their dashboard.
The current process just doesn't flow. When a user clicks to confirm their email, they are taken to a blank page where I am submitting a hidden form to create a lead object with their information and once the hidden form is submitted the dashboard page is loaded- It's extremely messy. The URLS are changing after several seconds and It will confuse users.
I want to create a lead object once they click the confirm email link. I have the current process routing the user through the leads_controller new and create methods and then they are automatically directed to their dashboard. I am using the devise sign_in_count attribute to make sure this is their first time signing in. If this is their first time signing in, I direct them through the leads controller to generate a lead with their information.
I am looking to generate the lead object while I am loading the dashboard page once the user selects the email confirmation link.
application_controller.rb
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  def account_url
    return new_user_session_url unless user_signed_in?
    case current_user.class.name
    when "Business"
      business_root_path
    when "Lender"
      lender_root_path
    else
      root_path
    end if user_signed_in?
  end
  def after_sign_in_path_for(resource)
    if resource.sign_in_count == 1
      new_lead_path
    else 
      stored_location_for(resource) || account_url
    end
  end
end 
leads_controller.rb
class LeadsController < ApplicationController
    before_filter :authenticate_user!
    include Databasedotcom::Rails::Controller
    def new
      @lead = Lead.new
    end
    def create
      @lead = Lead.new(params[:lead])
      @lead['RecordTypeId'] = 'XXXXX'
      @lead['OwnerId'] = 'XXXXX'
      @lead['FirstName'] = "XXXXXX"
      @lead['LastName'] = "XXXXX"
      @lead['Company'] = "XXXXX"
      @lead['Email'] = current_user.email
      @lead['IsConverted'] = false
      @lead['IsUnreadByOwner'] = true
      if @lead.save
        redirect_to lender_root_path
      end 
    end 
end
new.html.erb (this is the hidden form that is submitted to create a new lead object
<div class="container content">
    <%= form_for @lead do |f| %>
    <div class="field">
      <%= f.hidden_field :LeadSource, :value => 'Lending Loop' %>
      <%= f.hidden_field :Status, :value => 'Registered' %> 
    </div>
    <div class="actions">
      <%= f.submit :id => "hidden-submit", :style => "display: none;" %>
    </div>
    <% end %>
</div>
<script>
$(function () {
    $('#hidden-submit').click();
});
</script>
lender_account_controller.rb
class LenderAccountController < ApplicationController
    before_filter :authenticate_user!
    include Databasedotcom::Rails::Controller
    def dashboard
      render layout: 'simple'
      @leads = Lead.all
    end
end
 
    