title: format.js vs format.html in Rails
body: <p>I want to load a partial using AJAX in my <code>create</code> action.  From tutorials I know the way to do this is to include the line <code>format.js</code> alone by itself in the <code>respond_to</code> block and create a <code>create.js.erb</code> file.  But I have code in my <code>create</code> action which I need executed.  If I put all of this code within a <code>format.js {}</code> block the partial doesn't get loaded.  I guess I'm not sure what should be included inside this block?</p>
  
  <p>This sort of works:</p>
  
  <pre><code>def create
    respond_to do |format|
  
    format.html do
      session[:user_params].deep_merge!(params[:user]) if params[:user]
      @user = User.new(session[:user_params])
      @user.current_step = session[:user_step]
      if params[:prev_button]
        @user.previous_step
      elsif @user.last_step?
        @user.save
      else
        @user.next_step
      end
      session[:user_step] = @user.current_step
      if @user.new_record?
        render :new
      else
        session[:user_step] = session[:user_params] = nil
        flash[:success] = "Welcome to Friends First!"
        redirect_to @user
      end
    end
    format.js
  end
  end
  </code></pre>
  
  <p>My <strong>new.html.erb</strong> looks like this:</p>
  
  <pre><code>&lt;%= form_for(@user, :html =&gt; { :class =&gt; "form-horizontal" }, remote: true) do |f| %&gt;
    &lt;%= render 'shared/error_messages' %&gt;
  
    &lt;div id="partial"&gt;
      &lt;%= render "#{@user.current_step}", :f =&gt; f %&gt;
  &lt;/div&gt;
  
  &lt;div class="control-group"&gt;
    &lt;div class="controls"&gt;
      &lt;%= f.submit "Previous", class: "btn btn-primary", :name =&gt; "prev_button" unless @user.first_step? %&gt;
      &lt;%= f.submit "Next", class: "btn btn-primary" %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
    
  
  <p>But for some reason <code>@user.first_step?</code> is not working once I load a partial.</p>
  
  <p><strong>create.js.erb</strong></p>
  
  <pre><code>$("#partial").html("&lt;%= escape_javascript(render('step2')) %&gt;");
  </code></pre>
  
  <p>What I really want is this: <code>render(@user.current_step)</code></p>