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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:48:22+00:00 2026-05-22T02:48:22+00:00

I have a functionality of posting messages to a group which works using AJAX

  • 0

I have a functionality of posting messages to a group which works using AJAX via Jquery. When I click on the “Post” button which is the value of the submit_tag, javascript is rendered and the page without reloading displays the latest message posted. Basically the post_message.js.erb file is called. I am making use of the following tutorial to implement the same:- http://railscasts.com/episodes/136-jquery

The code for post_message.js.erb looks like this:-

$("#new_post").before('<div id ="new_post"><%= escape_javascript(flash.delete(:notice)) %></div>');<!--TO-DO the flash messages aren't yet enabled/working-->
$("#latest_post").prepend("<%= @group_post.message %> by <%=  Investor.find(@group_post.post_by).first_name %> <div class=contentdispgrp> <%=  distance_of_time_in_words(@group_post.created_at,Time.now) %> ago</div> <br/><br/><hr/>");
$("#post_msg")[0].reset();

The part of the form which would otherwise render HTML and display the posted message with reloading the page looks like this:-

<%form_for  :group_post, @group_post, :url => {:action => :post_message, :id => params[:id]},:html => {:multipart => 'true', :id => 'new_post'},:id => 'post_form' do |f| -%>
    Start Discussion:<label id="post_msg"><%=f.text_field :message%></label>
   <!--<%=f.file_field :photo%> -->
   <%=submit_tag "Post"  %></p>
<!--<input type="button" value="Reset Form" onClick="this.form.reset()" />-->
  <%end%>

<div id = "latest_post"> </div>
<%for a in @group_all_posts %>
<%= a.message %> by <%=  Investor.find(a.post_by).first_name %> <div class ="contentdispgrp" id="style_chck"> <%=  distance_of_time_in_words(a.created_at,Time.now) %> ago </div><br/><br/> <hr/>
<%end%>


</tr>

I want to empty the text field also along with the above already implemented functionality. I guess , I need to some how make use of the Javascript reset method , but somewhere I am not using it correctly.

Kindly help me with the same.

Thanks for your help..

[EDIT]

Code for post_message in my groups controller.

def post_message 
      @investor_group = InvestorGroup.find(params[:id])


      unless @current_user.is_an_existing_member_of_group(@investor_group)
        flash[:notice] = "Please join this group to participate in discussions"
        redirect_to :action => :show, :id => @investor_group and return # try to find out what exactly does this command do with return stmnt
      else
        @group_post = GroupPost.new(params[:group_post])
      end
      #@group_post = GroupPost.new(params[:group_post])

      investor_id = session['investor_id']
      @group_post.investor_group_id = @investor_group.id
      @group_post.post_by = investor_id
      if @group_post.message.blank?
         flash[:notice] = 'Post can\'t be blank.'
      end
      if @group_post.save
        flash[:notice] = 'Post was successfully created.'
       # redirect_to :action => :show, :id => params[:id] - removed after trying to implement ajax via jquery
      else
        flash[:notice] = 'Post was not successfully created.'
      end


      respond_to do |format|
        format.html {redirect_to :action => "show", :id => params[:id]}
        format.js
      end

  end
  • 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-22T02:48:22+00:00Added an answer on May 22, 2026 at 2:48 am

    I assume you want something like this:

    $('#post_msg input').val('');
    

    That will clear the message input box value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JQuery AJAX POSTing data to my backend C# WebForm. It POSTs
How can I have that functionality in my game through which the players can
We have a requirement to increase the functionality of a grid we are using
I have subclassed Form to include some extra functionality, which boils down to a
I want the functionality of a radio button, yet have the option of choosing
Hey So I have a question about posting using an XMLHttpRequest. In theory, if
For a given class I would like to have tracing functionality i.e. I would
I have created some extra functionality on my Linq-to-SQL classes to make things easier
We have a piece of functionality that is used by several different applications (clients)
I have been searching everywhere for the following functionality in Lisp, and have gotten

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.