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 6101653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:31:28+00:00 2026-05-23T13:31:28+00:00

I am trying to use jQuery with Rails and AJAX to accept a post

  • 0

I am trying to use jQuery with Rails and AJAX to accept a post from a user, and update the relevant elements on the page to display the new post.

I have successfully set a post model and controller in my app, and adapted it to accept form submissions with AJAX. I know that the AJAX form submission is working, but I can’t get any elements on my page to reload. I have a Post model, Posts controller, a _post_form.html.erb partial that has a html form for posting, and the relevant create.js.erb file.

The create.js.erb file current contains (without the what_to_put_here):

 alert('ajax works!');
 $('#user_info').what_to_put_here?

When it contains just the alert, the file works and a dialogue comes up displaying the message. So, I am certain everything works. However, i just can’t figure out what code to user to update the user_info element and the posts table. I am using jQuery and jQuery UI for my javascripts.

So, how do I write in the create.js.erb file a way to update the posts table and the user_info current_user.posts.count?

The following is the show.html.erb file:

 <section>
 <%= render 'shared/discussion_overview' %>
 <% unless @posts.nil? %>
 <h3> Thoughts and Opinions </h3>
 <table class= "posts">
         <%= render @posts %>
 </table>
 <%= will_paginate(@posts) %>
 <% end %>
 <%= render 'posts/post_form' %>
 </section>

The posts partial _post.html.erb:

 <tr>
<td >
    <span class="post_header"><h4><%= link_to "#{post.user.first_name} #{post.user.last_name}", post.user %></h4></span>
    <p> <%= post.content %> </p>
</td>
 </tr>

And the _user_info.html.erb partial (which is referenced from application.html.erb) :

 <div id="user_info">
<h1><a href = "<%= user_path(current_user) %>" >
<%= "#{current_user.first_name} #{current_user.last_name}" %>
</a></h1>
<%= pluralize(current_user.posts.count, "post") %> <br>
<%= pluralize(current_user.discussions.count, "discussion")%> <br>

Joined <%= time_ago_in_words(current_user.created_at)%> ago.
 </div>
  • 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-05-23T13:31:28+00:00Added an answer on May 23, 2026 at 1:31 pm
    $('#user_info').html("<%= escape_javascript(render :partial => 'user_info')%>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use jQuery's ajax functionality to update data from a web
In my Rails app, I'm trying to use jQuery ajax to create a new
I am trying to use jQuery to make a synchronous AJAX post to a
I am trying to use the tabs function from jQuery UI in a Rails
I am trying to use Jquery / ajax in rails 3.0.7. I do not
I'm trying to use jQuery to get data from an ASP.NET web service (SharePoint
I'm trying to use jQuery UI tabs much like a Master Page in ASP.Net.
I am trying to use jQuery AJAX. What my requirement is, i wish to
I am trying to use JQuery to highlight the checkboxes checked by a user,
I am trying to use jQuery (latest version) & ajax to poll a mysql

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.