Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:38:41+00:00 2026-06-17T04:38:41+00:00

I want to load a partial using AJAX in my create action. From tutorials

  • 0

I want to load a partial using AJAX in my create action. From tutorials I know the way to do this is to include the line format.js alone by itself in the respond_to block and create a create.js.erb file. But I have code in my create action which I need executed. If I put all of this code within a format.js {} block the partial doesn’t get loaded. I guess I’m not sure what should be included inside this block?

This sort of works:

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

My new.html.erb looks like this:

<%= form_for(@user, :html => { :class => "form-horizontal" }, remote: true) do |f| %>
  <%= render 'shared/error_messages' %>

  <div id="partial">
    <%= render "#{@user.current_step}", :f => f %>
</div>

<div class="control-group">
  <div class="controls">
    <%= f.submit "Previous", class: "btn btn-primary", :name => "prev_button" unless @user.first_step? %>
    <%= f.submit "Next", class: "btn btn-primary" %>
  </div>
</div>

But for some reason @user.first_step? is not working once I load a partial.

create.js.erb

$("#partial").html("<%= escape_javascript(render('step2')) %>");

What I really want is this: render(@user.current_step)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:38:42+00:00Added an answer on June 17, 2026 at 4:38 am

    You can do all your logic and then handle proper format. Furthermore you can use more than one format for your views.

    There is and example from Diaspora source code:

      def create
        post = current_user.find_visible_shareable_by_id(Post, params[:post_id])
        @comment = current_user.comment!(post, params[:text]) if post
    
        if @comment
          respond_to do |format|
            format.json{ render :json => CommentPresenter.new(@comment), :status => 201 }
            format.html{ render :nothing => true, :status => 201 }
            format.mobile{ render :partial => 'comment', :locals => {:post => @comment.post, :comment => @comment} }
          end
        else
          render :nothing => true, :status => 422
        end
      end
    

    You shouldn’t do any redirects if something fail because user stay at page anyway. But you might want use client-side validation.

    So you might use format.js for your success case and reload part of your HTML using partial. For example:

    # create.js.erb
    $("#js-user-panel").html("<%= j render("users/panel", :user => @user %>");
    # ... create div with flash message here and etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to load PNG-file from resources. There is a roughly MFC-way (with CResourceStream
I want to load a DropDownList with possible Paises from my database. using System;
I want to load the form fields using json data. I am using extjs
I want to load data from MySql database to a HTTP form When I
I want to load a palette from a bitmap file I have created. The
I want to load defined folders into my website from same system, now I
Does anyone know how I can load a Ruby on Rails partial into a
I want to create two partial classes for the single aspx file. I am
I found a number of questions and answers regarding updating a partial using Ajax
I want to load the same view again by passing updated parameter from text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.